Home > UNIX > Vi Editor – Part 3

Vi Editor – Part 3

Problem 13
————
How to perform pattern search in vi editor?

Solution 13
————
open a file in vi editor in command mode then follow below commands..
/patn — searches forward for pattern patn. For e.g. to search for pattern “execute” use /execute
?patn — searches backward for pattern patn
n — repeat search in same direction along which previous search was made
N — repeat search in direction opposite to that along which previous search was made

Problem 14
————
how to substitute?

Solution 14
———–
Use below..
:5,10s/x/y/g — Substitute every occurence of “x” by “y” from line 5 to 10
:.s/x/y/g — Substitute every occurence of “x” by “y” in the current line only
:$s/x/y/g — Substitute every occurence of “x” by “y” in the last line

If you need confirmatory substituion then use “c” with “g” like below
:2,$s/x/y/gc

Note: Significance of “g” is to substitute every occurence in a line else first occurence of “x” will be replaced by “y” in every line only.

————————————————Note—————————————————
I am closing Vi Editor here for now. Hope this will help you all. Suggestions and Criticism are cordially welcomed and highly appreciated :-)..Enjoy learning

Check the Sybase Wiki @ sybasewiki.com
Categories: UNIX Tags:
  1. No comments yet.
  1. No trackbacks yet.