What can you do when you want to replace certain text strings with their “equivalents” or “substitutes” very fast?
Of course you can fire up your favorite text editor and start the well-known and frequently used ‘search-and-replace’ procedure.
Or you can do the same thing using sed, like this:
$ sed -i -e ‘s/this/that/g’ -e ‘s/foo/bar/g’ filename
But, if you have MySQL installed, you can find the replace utility very handy, like this:
$ replace this that foo bar — filename
So? Except for the fewer characters typed (in the case of replace), both commands had the same result, right? Right!
But replace can do the following in just one step:
$ replace this that that this — filenameor even
$ replace foo bar bar baz baz foo — filename1 filename2 filename3
replace is a utility written just to replace text strings and it does it very good.
sed, on the other hand, can do a lot (and then some) more, but it’s not for someone less experienced.
Visit The Light of the LAMP blog for more…