PERL - Practical extraction and reporting language is best suited for replacing text using regular expression in a large amount of files. To replace text in the files, just browse to directory in command prompt where the files resides and issue the following command:
perl -pi.bak -e 's/Find/Replace/g' *.html
perl -pi.bak -e "s/re[g]ex/regular expression/gi" *.html
The option 'p' is used to iterate over all the files names given on the command prompt, and not stop after processing just the first file. The 'i' option tells that all the files need to be edited in place, it does this by renaming the input file with the extension provided (like .bak), opening the output file by the original name. The option 'e' is used to execute the statements given on command line itself, instead of using a script file. This type of statements are also called perl one-liners. Option 's' denotes substitution and 'g' denotes search in the whole text and get all the occurrences. Option 'i' denotes case in-sensitive search. You can also use regular expression to find and replace text in the files. Parameter (-0777) which will make Perl look at all lines at once.
perl -0777 -pi.bak -e 's/\t*<TITLE.*>(.*)<\/TITLE>//gi'
#/bin/sh
echo "TITLE"
find . -name '*.php' | xargs perl -0777 -pi.bak -e 's/\t*<TITLE.*>(.*)<\/TITLE>//gi'
# Delete out all multiple linebreaks
echo "linebreaks"
find . -name '*.php' | xargs perl -0777 -pi.bak -e 's/\n+/\n/g'
echo "TITLE"
find . -name '*.php' | xargs perl -0777 -pi.bak -e 's/\t*<TITLE.*>(.*)<\/TITLE>//gi'
# Delete out all multiple linebreaks
echo "linebreaks"
find . -name '*.php' | xargs perl -0777 -pi.bak -e 's/\n+/\n/g'
Windows perl distribution (ActivePerl) can be downloaded from the ActiveState website.