LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-29-2004, 07:07 PM   #1
Axion
Member
 
Registered: Jan 2003
Location: Albany, NY
Distribution: Slackware 9.1, Gentoo 2004.1
Posts: 153

Rep: Reputation: 30
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.
 
Old 07-29-2004, 07:40 PM   #2
Muzzy
Member
 
Registered: Mar 2004
Location: Denmark
Distribution: Gentoo, Slackware
Posts: 333

Rep: Reputation: 30
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.
 
Old 07-29-2004, 07:53 PM   #3
Axion
Member
 
Registered: Jan 2003
Location: Albany, NY
Distribution: Slackware 9.1, Gentoo 2004.1
Posts: 153

Original Poster
Rep: Reputation: 30
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.

Last edited by Axion; 07-29-2004 at 08:01 PM.
 
Old 07-29-2004, 09:40 PM   #4
Axion
Member
 
Registered: Jan 2003
Location: Albany, NY
Distribution: Slackware 9.1, Gentoo 2004.1
Posts: 153

Original Poster
Rep: Reputation: 30
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

Last edited by Axion; 07-30-2004 at 06:16 PM.
 
Old 07-29-2004, 09:51 PM   #5
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix, 98,2000 + various
Posts: 3,171

Rep: Reputation: 51
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script question Whiteghost Programming 17 09-10-2005 06:52 PM
Shell script question paraiso Linux - Newbie 2 05-15-2005 01:55 AM
Shell script question... defa0009 Linux - General 7 04-26-2005 08:16 PM
Shell script question. siaful Linux - Newbie 1 04-29-2004 05:01 PM
Shell script question rytrom Linux - Newbie 4 01-28-2004 07:20 AM


All times are GMT -5. The time now is 03:06 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration