How to do a search and replace in multiple files using perl and linux
February 26, 2008 on 11:36 am | In linux, programming, perl |
So you’ve got 100 files in a directory and you want to replace the string “foo” with “bar”. Stop before you waste your time opening up every single file and making the change, you can make all of the changes with a single line of perl.
perl -pi -w -e 's/foo/bar/g' *\.php
On his blog, Liam Delahunty explains what each of the following command line switches means.
-e means execute the following line of code.
-i means edit in-place
-w write warnings
-p loop
There you have it - a nice and easy Perl solution that should save you tons of time.
Like this story? Share with others on:
 
del.icio.us
digg
reddit
furl
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds.
Valid XHTML and CSS. ^Top^
41 queries. 0.183 seconds.
