ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have seen perl scripts that do this and agree they are very elegant. However in this case it's more about the journey. ie: determined to use bash no matter how ugly it turns out.
That plus my perl knowledge ends at "Hello World"
*Not to say my bash knowledge goes much deeper.
If you use KDE, you could save yourself a lot of work if you type in "audiocd:/" in the konqueror file browser.
It will look up the CDDB data and produce an OGG and MP3 psuedo directory. You only have to drag the MP3 files you want and drop them into the target directory to start the transcoding process.
You may need to install a KDE package for the audiocd:/ protocol.
TRACK1=$(cat cdinfo.txt | grep TTITLE0 | sed 's/TTITLE0=//')
TRACK2=$(cat cdinfo.txt | grep TTITLE1 | sed 's/TTITLE1=//')
...
if [ -a new_track01.cdda.wav ]; then
mv new_track01.cdda.wav "$TRACK1".mp3
fi
...
You can use a loop:
Code:
#missing second expression means loop forever unless there's a break statement
for((tnum=0; ; tnum++))
do
NEXT_TRACK="$(sed -n "s/^TTITLE$tnum=\(.*\)\$/\1/ p" cdinfo.txt)"
#if TTITLE$tnum was not found, then exit the loop
if [ -z "$NEXT_TRACK" ] ; then break; fi
mv "new_track$tnum.cdda.wav" "$NEXT_TRACK.mp3"
done
This isn't a great way since sed ends up having to read the entire cdinfo.txt file once for every track, but it does work. It also assumes that there is no "hole" in the numbering of the tracks, and that they start from 0.
One reason I often advocate perl over python or ruby is that a perl script is more valuable to your employer in the long run, because more people know it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.