Saturday, September 24, 2011

FIND and REPLACE in unix

Many times we want to find and replace all the occurences of  one word in a file to another word in Unix. Using the power of vi editor, it can be done easily.
Here is the syntax for the same in unix

:1,$s/oldword/newword/g

example
To find and replace all occurences of "erp" with "BERP" in a file, we have to do the following->
Open the file in vi editor, and issue the following command
:1,$s/erp/BERP/g

No comments: