Simple recursive search and replace with perl
I recently needed to do a mass search and replace for some content on my website. I vaguely recalled doing this in the past with find, sed, and/or xargs so decided to ‘Google’. My memory was jogged when I found this example:
find *.ext -type f -exec sed -i ‘s/OldText/NewText/’ {} \;
and I was very pleased to find that you can also do this with perl:
(Current dir only, making a backup with an appended ~)
perl -pi~ -e ‘s/OldText/NewText/’ *.ext
(Recursive, editing the file directly)
find *.ext | xargs perl -p -i -e s/OldText/NewText/g
(Visited 1,071 times, 1 visits today)