Quickie: Multiple File Search and Replace
If you've ever run into the necessity to change the same data over multiple files you know how hard it is to go through each and every file and update it by hand or at best do an indiviual regex on each. Here's how you can make the changes all in on fell swoop.
perl -pi -w -e 's/searchregex/replaceregex/g;' *.fileextension
-w display any warnings
-i in place edit
-p loop over files
-e execute this line of code
Here's an example:
perl -pi -w -e 's/\x0D//g;' *.txt
This looks for those pesky ^M characters and replaces them with nothing.
- Login to post comments


![[FSF Associate Member] [FSF Associate Member]](http://www.ossolutions.org/lores/img/fsfMember.png)
Subscribe to this Feed