Here’s a classic that I originally published 20 February 2003 – 11:14. This entry was the #1 most popular post between 11/19/2005 and 11/13/2006, receiving 16,443 page views (13,653 unique) during that time.
Since it’s damn near impossible to find online the simplest way to scan a Unix directory of files, search for one text pattern, and replace with another, I am now archiving the simplest method I could find (which I’ve tested and have proven that it works beautifully). Simply cd to the directory where your files live, modify (or leave) the *.php to match the file type you are modifying, then run the following at the command line:
for fl in *.php; do
mv $fl $fl.old
sed ‘s/FINDSTRING/REPLACESTRING/g’ $fl.old > $fl
#rm -f $fl.old
Uncomment rm -f $fl.old if you don’t want to bother keeping a copy of the old files. Simple, eh? It’s all about sed, baby.email or RSS feed. ]