Quickly find/replace stuff in files

Posted May 8th, 2010 in Bread-crumbs and tagged by Tobias

I had to replace a string in a bunch of files and wanted to do it quickly.
1. cd to the directory where your files live.
2. Run this:


for i in *; do perl -i -pe 's/oldtext/new better  text/g' $i; done

..or no perl? Use sed.


for i in *; do sed -e 's/oldtext/newtext/g' -i $i;  done

Comments are closed.