I developed a shell script for renaming my mp3 files. My script uses Perl for full regular expression support (so I don’t have to escape the patterns like in SED).

The script uses Perl and regular expressions to normalize the file names. Basically, it removes junk from the file name; spaces, covert to title case. The patterns reside in a preset file since several replacements are necessary. Each preset file deals with a slight different renaming profile. My current development efforts involve applying these replacement patterns to the text inside playlist and xml files. I want to process the text inside these files; thus align the renamed filenames with the pointers in the playlist files. Eventually, the script would help me rename my mp3s and iTunes database (without importing all my audio files once again), yet it has several purposes beyond mp3 renaming.

The script performs a recursive search and finds files with these extensions (m3u, sfv, and xml). It iterates (while loop) through an external file with regular expression patterns. Then it combines the patterns and places them in a variable, which is passed to Perl. The script below performs this task (yet has not been thoroughly tested). It has a major shortcoming that the Perl line works on the entire file when it should only replace the lines with mp3 pointers. Here’s the call for assistance since I am having code block. Maybe, someone could help me with different logic or a traditional grep solution. I just need fresh ideas for my shell script.
Code:
find ./ -regex ".*\(m3u\|sfv\|xml\)$" -type f -print | while read FILE
	do 
		while read -r REGEX REPLACE line
		do
			CODE="$CODE; s/$REGEX/$REPLACE/g"
		done < "$PRESET"
#PRESET may contain over twenty five regex patterns for complex renaming task
		perl -pi.bak -e "$CODE" $FILE	
done
btw I am doing this script in Bash, because Perl is foreign territory.