Search and Repalce a particular word in VI Editor(UNIX)

While using VI editor in UNIX many of us come across a need to Replace a particular word with another word.
Say our file containing a text information as follows
"Ramu and giri are really nice friends. Both of them work in the same office. Ramu working as SWE and giri working as Accountant"
In the above text information if we want to replace all instances of the word Ramu with Krishna the following steps will help
Press Esc
give :
type like this

%s/Ramu/Krishna/g
or
1,$s/Ramu/Krishna/g

Some more similar tricks here
More about Vi


1 comments to "Search and Repalce a particular word in VI Editor(UNIX)"

  • for confirming the replace of the word use 'c' suck as

    %/xyz/abc/gc

    This will ask for ur confirmation before replacing the pattern xyz with abc.

Post a comment

Whoever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs, u can at least use Name/URL option which doesn’t even require any sign-in, The good thing is that it can accept your lovely nick name also and the URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")

Popular Posts

Enter your email address:

Buffs ...

Tags


Powered by WidgetsForFree

Archives