Search and replace in multiple files
February 25th, 2009
If you ever need to search and replace strings throughout a bunch of files here’s a neat, somewhat alternative, way to do it.
for file in `ls **/*.txt`;do perl -pi -w -e ’s/SEARCH_FOR_THIS/REPLACE_WITH_THIS/g;’ $file; done
The nested ‘perl’ command can work kind of like ’sed’. Here are what the arguments being passed in mean:
-e means execute the following line of code.
-i means edit in-place
-w write warnings
-p loop















