Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
I'm fairly new to Linux and totally new to bash scripting. I've been using LAME to convert .wav files to .mp3 files and the task has become a tedious one so I'm trying to simplify things.
When I use XMMS with its CD-Writer plugin to extract songs from a CD I end up with this:
Track\ 01.wav
Track\ 02.wav
Track\ 03.wav
and so on...
My ultimate goal is to end up with a directory of songs that appear like this:
band_name-song_name.mp3
band_name-song_name.mp3
band_name-song_name.mp3
and so on...
Currently I have a script which I call "lameall" and it reads:
--begin script--
#!/bin/bash
# Rename disk writer's output by taking out "Track\".
# convert *.wav into *.mp3
LIST=$(ls *.wav)
for i in $LIST; do
ORIG=$i
DEST=$(ls $i | cut -d "." -f 1).mp3
lame -h $ORIG $DEST
echo "done converting $i, removing.."
rm $i
done;
echo LAME complete!
--end script--
This works pretty well, but I'm not satisfied. I know the first part of the script is sloppy and it always results in errors if there are less than 15 tracks in the directory (no such file errors).
This script ultimately leaves me with:
01.mp3
02.mp3
03.mp3
and so on...
How can I use a while loop in renaming the "Track\ 01.wav" to "01.wav" so that I won't get the "no such file" errors? I need to take out the "Track\" because I run into problems with LAME.
How can I write an interactive script so that it will ask me for the band_name then ask me for each song_name then it automatically prepends the song_name with the band_name?
Like this:
band_name-song_name.mp3
I hope I am clear here. Remember, I'm a newbie so forgive me if this is stupid...this is more of a scripting exercise for me than anything else, but it would also be a useful script for me.
"For the first part, why not implement a for loop to look at each song and use sed to remove the "Track \"."
What is sed and how would I implement it in this case? Could you give me an example?
"As for the second part, can't help you there as I don't know how XMMS lists the songname/bandname. "
As I said earlier XMMS outputs:
Track\ 01.wav
Track\ 02.wav
Track\ 03.wav
and so on...
I'm trying to first rename the "Track\ number.wav" to "number.wav" so that LAME can work with it. Then after LAME does its job I want to be presented with questions which will accept answers from me.
The first question should be, "what is the band name?"
I would answer, for instance, "iron_maiden".
Then it should as me, "what is the name of the first song (01.mp3)?
I would answer, "song_name".
Then it should prepend the song_name with the band_name and add the .mp3 extension so that it appears as such:
band_name-song_name.mp3
Then it should ask me, "what is the name of the second song (02.mp3)?
What is sed and how would I implement it in this case? Could you give me an example?
twantrd@debian:~/testing$ echo Track\ 01.wav | sed 's/.* //'
01.wav
As you can see, the way I've used sed removes "Track ".
Code:
Then after LAME does its job I want to be presented with questions which will accept answers from me
LIST=$(ls *.wav)
for i in $LIST; do
echo "What is the bandname?"
read band
echo "What is the name of the first song?"
read song
#ORIG=$i #As you don't need this.
DEST=$(ls $i | cut -d "." -f 1).mp3
lame -h $i $DEST
echo "done converting $i, removing.."
rm $i
done;
I've given you the syntax on how to ask questions and how to grab the input. Now, you can change the script around to suit your needs. Let me know if you have any questions...good luck
Thanks for that, but I got it all figured out last night.
I didn't use sed though, I used more code to do the work as follows:
LIST=$(ls Track* | cut -c 7-8)
for i in $LIST; do
ORIG=Track_$i.wav
DEST=$i.wav
mv $ORIG $DEST
done;
I guess I need to do some learning about sed
Also, your way of grabbing the band name and song name runs you through a loop of band names when you only need it once. I did it this way:
LIST=$(ls *.mp3 | cut -c 1-2)
echo -n "Please type the name of the band and press [Enter]:"
read bname
for i in $LIST; do
echo -n "Please type the name of the song for $i.mp3 and press [Enter]:"
read sname
mv $i.mp3 $bname-$sname.mp3
done;
This way I am only asked for the band name once and then for each song name.
Thanks for your replies! Man, I'm so happy I moved to Linux...I love this stuff!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.