Tidbit - Find and Replace Text in Files with Perl
- TidBits:
In our Nagios / Webinject environment, we have alot of text configuration files. Sometimes a simple product update requires me to update LOTS of these files. A majority of the time, a find and replace is all I need. Using perl from the command line, I can quickly update a bunch of files saving countless hours of tedious file updates.
Example - Changing text string of Nagios WebInject test cases...
perl -pi -w -e 's/string1/string2/g;' *.xml
This command will replace "string1" with "string2" in all our XML files in the current directory. Of course I like to take a backup of the entire directory before I run something like this just in case.
- MWalker's blog
- Login to post comments
-

Recent comments
23 weeks 5 days ago
27 weeks 6 days ago
45 weeks 2 days ago
48 weeks 3 days ago
1 year 6 weeks ago
1 year 13 weeks ago
1 year 13 weeks ago
1 year 18 weeks ago
1 year 22 weeks ago