Re: Bash command -cut (oops last message truncated)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



neidorff wrote:
> Hi,
> 
> This baffles me, but should be very simple.
> 
> I have a directory with names of audio files.  I want to convert from
> one audio format to another.  No problem there. 
> 
> I want to create a script to do handle the change of file extension
> chores.  I came up with this:
> 
> #!/bin/bash
> FILES=$(ls *.flac | cut -f1 -d\.)
> for i in $FILES; do
>     echo converting: $i
>     flac -sd $i.flac -o  wav/$i.wav
> done
> 
> The first file is named "01 Introduction.flac"  and the problem that I
> have is that the first time I go through the for loop, "i" contains "01"
> the next time "i" contains "Introduction".  Since I set the delimiter
> (with the -d option in cut) to "." (escaped) why am I not having "i"
> contain "01 Introduction" the first time through the for loop?  What
> obvious thing am I missing here?
> 
> Thanks,
> 
> Mark
> 
Part of the problem is the spaces in the file names.  The loop is
treating spaces as delimiters for the data in $FILES. You may find
using basename works better for this application.

for i in *.flac ; do
	name=$( basename "$i" .flac )
	echo Converting $name
	flac -sd "$name.flac" -o "wav/$name.wav"
done

a slightly different way to do it would be:

for i in *.flac ; do
	name=$( basename "$i" .flac ).wav
	echo Converting $name
	flac -sd "$i" -o "wav/$name"
done

In ether case, you have to enclose the file name in quotes because
of the spaces.

Mikkel
-- 

  Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux