The main change I would recommend is to first prepare a file containing a list of the lyrics files. Running a directory list or find command on such a large number of files will take time. You don't want that inside a loop. Preparing a directory listing to work with before your loop will save a lot of time.
One thing you can do is use a single sed command instead of all of the pipe commands.
sed 'command1;command2;command3;command4'
or
sed -e 'command1' -e 'command2' -e 'command3' -e 'command4'
You can also create a file containing your sed commands and call the sed command like: "sed -f replacemp3s.sed". That would allow you to debug the sed commands as a separate entity.
If you do use sed to process the list of mp3 music files, you could use the memory registers to enable print the parts that match in the repacement string. This is commonly used to cut out parts of a line which you want to do.
Maybe this example will give you some ideas:
Code:
echo '01 - Dungen - Panda.mp3' |
sed -n 's/^[[:digit:]][[:digit:]]* - \(.*\) - \(.*\).mp3/\1\t\2/p' |
while read name artist; do
echo name=$name,artist=$artist;
done
name=Dungen artist=Panda
or this one:
Code:
eval $(echo '01 - Dungen - Panda.mp3' |
sed -n 's/^[[:digit:]][[:digit:]]* - \(.*\) - \(.*\).mp3/name="\1" artist="\2\"/p')
~> echo $name
Dungen
~> echo $artist
Panda
For other ideas, look at the `-f' option for grep. You could construct regular expression strings from the list of mp3 files and use that in a search of a list of the lyric files. Or you could use variables in a grep or sed command to locate the matching lyrics file from the list.
The '-n' option I used in the sed example suppresses the output. The later `p' command after the replacement prints the line only if there was a match. This can eliminate problems if a filename doesn't match the pattern. I would recommend that you move the file to another directory after renaming it, since the pattern before and after are similar. Also using a text file of the mp3 directory for debugging until you get the script correct. You could print out the mv command line to create a script of mv commands. This would allow you to visually inspect it for problems before actually executing it.
At work I need to perform something similar, locating files with leading zero's and removing them from the filenames. There are thousands of files. I can access the directory from my workstation, but don't have permission to rename them. So I construct a windows batch file (using sed in a cygwin script), redirect the output to a batch file on the server, and then log in to the server and run the script.
Good Luck!