[linux-audio-user] converting large number of ogg's to mp3's

mdeboer at iua.upf.es mdeboer at iua.upf.es
Sat Jan 8 15:57:28 EST 2005


>> sox /shared/music/albums/albumName/song.ogg ~/mp3/albumName/song.mp3
> [...]
> cd /shared/music/albums
> find . -name \*.ogg -print -exec sox {} {}.mp3 \;
> 
> This will take any file under /shared/music/albums and create an mp3
> file with the same name plus a .mp3 extension. 
> [...]

To change the extension, you could use sed.

find . -name "*.ogg" | while read filename; do \
  sox "$filename" "`echo $filename | sed -e 's/\.ogg$/.mp3'`" \
done

To explain this: the output of find will be feeded, line by line, to the
expression inside the while loop, setting the value of filename to each
line. The expression inside the ` ` will be evaluated first - it's
result is the value of $filename parsed by the regular expression that
replaces .ogg at the end of the line (end-of-line is represented by the
$ after ogg) with mp3.

Also note the use of "*" instead of \*, which I guess is a matter of
taste. Adding another | sed, you could easily substitute the folder as
well.

If you are not familiar with command-line scripting, this might all seem
a bit complicated, but once you get used to it, you'll see it's really
straightforward. And extremely powerful. 

maarten



More information about the Linux-audio-user mailing list