Brian Hartsock's Blog

Linux: Find and Replace in Files

by bhartsock on Jun.13, 2007, under Linux

Thanks to Jon H., I can now do find and replace in files on Linux machines from the command line. Its pretty simple, but I had never bothered to figure it out.

Here are two examples. The first is for just one file, the meat and potatoes are in the second example, which does a find and replace in all PHP files.

1
2
sed -i -e "s/TOREPLACE/REPLACEMENT/g" temp.txt;
sed -i -e "s/TOREPLACE/REPLACEMENT/g" `find -name '*.php'`;

Super helpful.

Post to Twitter Post to Digg Post to Facebook Post to Reddit


1 Comment for this entry

Leave a Reply