Replace in place

ript>

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 — filename

or 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…

One Reply to “Replace in place”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.