Isolate lines in a text file and perform replacement



I developed a shell script for renaming my mp3 files. The script uses
Perl and regular expressions to normalize the file names. The patterns
reside in a preset file. My current development efforts involve
applying these regex patterns to playlist and xml files. I want to
process the text inside the these files. Eventually, the script would
help me rename my itunes database, 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 placed them in a variable, which is passed to Perl. The
script below performs this task (yet has not been thorough 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 the shell.

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"
echo "$CODE"
echo "perl -pi.bak -e "s/$REGEX/$REPLACE/g" $FILE"
#PRESET may contain over twenty five regex patterns
done

btw I am doing this script in Bash, because Perl is foreign territory.
.



Relevant Pages

  • Isolate lines in a text file and perform replacements
    ... I developed a shell script for renaming my mp3 files. ... that this newsgroup revolves around Perl, yet my script uses Perl for ...
    (perl.beginners)
  • PERL with grep
    ... I'm a newbie in PERL and wish to seek some help with regards to pattern matching PERL and grep. ... It however produces an error - I'm unable to pass multiple patterns for grep? ... Could anyone help me out by showing an implementation of a PERL script to automate this task? ...
    (perl.beginners)
  • Isolate lines in a text file and perform replacements
    ... I developed a shell script for renaming my mp3 files. ... that this newsgroup revolves around Perl, yet my script uses Perl for ... The patterns reside in a preset file. ... external file with regular expression patterns. ...
    (comp.lang.perl.misc)
  • Re: Isolate lines in a text file and perform replacement
    ... Perl and regular expressions to normalize the file names. ... applying these regex patterns to playlist and xml files. ... The script performs a recursive search and finds files with these ...
    (comp.unix.shell)
  • 2005-10-23 [de.comp.lang.perl.cgi] FAQ
    ... Programmiersprache Perl in CGI-Scripten. ... Wo gibt es Dokumentation über Perl und CGI? ... Hilfe zum Programm perldoc kann man mit 'perldoc perldoc' ... Mein Script läuft nicht bei meinem Provider. ...
    (de.comp.lang.perl.cgi)

Loading