LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   shell script question (https://www.linuxquestions.org/questions/programming-9/shell-script-question-211224/)

Axion 07-29-2004 07:07 PM

shell script question
 
I am writing a shell script to convert APE to FLAC files for my Grateful Dead live show collection. The problem is, the resulting filename is *.ape.flac, and I want to drop the .ape part somehow....maybe sed? I don't know, I'm a newbie at shell scripting (but not programming)....not looking for a howto...just the best way to accomplish this small task. Thank you.

Muzzy 07-29-2004 07:40 PM

I love shell questions! :)

I think piping the output of an ls into a loop, and sed'ing (as you suggested) the filename is the way to go here. Be careful with typing all the different types of quotes!

Code:

ls *.ape.* | while read file; do mv "$file" "`echo $file | sed 's/\.ape\././'`"; done
A test i used to check that the above works, even if spaces are included in the filename:

Code:

$ touch "the planet of the apes.ape.flac"
$ ls *.ape.* | while read file; do mv "$file" "`echo $file | sed 's/\.ape\././'`"; done
$ ls
the planet of the apes.flac

Let me know how it goes please,
Mark.

Axion 07-29-2004 07:53 PM

Thanks for the quick reply...I'm going to try it right now...

Edit: Success. Thank you very much for the example...I'm going to leave it at that because it works perfectly. In a few I will post the entire shell script for anyone interested.

Axion 07-29-2004 09:40 PM

Some might find this useful, who knows...

Code:

# ape2flac
# converts monkey's audio files to flac format
# required: mac, flac, cfv
#        mac: http://www.personal.uni-jena.de/~pfk...nary_Linux.zip
#      flac: http://prdownloads.sourceforge.net/f...ar.gz?download
#        cfv: http://prdownloads.sourceforge.net/c...ar.gz?download
# by axion@37.com

# define variables
export MAC="/usr/bin/mac"
export FLAC="/usr/bin/flac"
export ENCODE="$FLAC -8"

# search recursively for ape files and decode to wav any found
find . -name '*.ape' -exec $MAC {} {}.wav -d \;
ls *.ape.* | while read file; do mv "$file" "`echo $file | sed 's/\.ape\././'`"; done

# encode wav files to flac
find . -name '*.wav' -exec $ENCODE {} \;

# delete any leftover ape or wav files
find . -name '*.ape' -exec rm -f {} \;
find . -name '*.wav' -exec rm -f {} \;

# generate playlist and checksums
find * -type f -name '*.flac' > "00 - playlist.m3u"
/usr/local/bin/cfv -C -t md5 -f "00 - checksums.md5" *.flac
/usr/local/bin/cfv -C -t sfv -f "00 - checksums.sfv" *.flac


whansard 07-29-2004 09:51 PM

the rename command is simple. i used this for re-encoding some mp3's.
for a in * ; do
cd "$a"
for i in *.mp3 ; do
nice -n 15 lame --preset 150 -b 64 -B 224 --lowpass 17k "$i"
rm "$i"
done
rename .mp3.mp3 .mp3 *
cd ..
done


that was to go through a bunch of directories. rename takes 3 arguments. the text you wish to change, what to change it to, and what files to perform the changes on.
so rename ".ape.flac" ".flac" *.flac would be good for you.


All times are GMT -5. The time now is 01:13 AM.