Ticker

6/recent/ticker-posts

find and replace in vi editor

unix vi editor exampledon't confuse this with find command in UNIX , VI editor provides easy commands tosearch and replace, perform global search and local search. I would suggest practice it a few times to get hold of it and understand its working. we use ":s" (substitute) command forsearch and replace in VI editor.

The  ":s"   command look for a particular pattern and replaces with provide substitution, here are some examples of usingsearch and replace in VI editor.
In Vi editor search and replace, "g" stands for global search here which means all occurrence of a particular word in a line changed rather than just first word, which is default behavior if you don't use global search


:%s/Stock/Equity/g
    This is an example of global search it will replace all occurrence of word "Stock" in file with word "Equity". Its also equivalent to following command ": 0,$ s/Stock/Equity/g" which actually tells that search from fist to last line.

:%s/Stock/Equity/gc
    This is similar to first command but with the introduction of "c" it will ask for confirmation

:%s/Stock/Equity/gci
   This is command is global, case insensitive and ask for confirmation. to make it case Sensitive use "I"

Post a Comment

0 Comments