use perl
Redirection from a file to the same file usually results in an empty or close to empty file. Perl is great for this activity, for example:
perl -i.old -pe 's/192\.168\.1\.2/10\.10\.10\.10/g' httpd.conf
The -i.old will move the original file to .old in the event you break it. WARNING: run the command twice and your backup is overwritten.
The -pe is actually 2 flags the p is an implied print loop over every line in the file and the e 'code' indicates you are giving perl the code on the command line. Note the g in the end of the code, if you leave this off then a line like this:
192.168.1.2 happy fun 192.168.1.2
will end up looking like:
10.10.10.10 happy fun 192.168.1.2
|