Find and Replace Vi

Posted: August 6, 2013 in Linux
Tags: , , ,

Lot of times we Will be in a situation to find and Replace some characters in a file.

say my file contains

"apple"
"mango"
"orange"

and now i need to remove all quotes from the file , use the following substitution vi command

 
:1,3s/\"//

Explanation :

– press escape to move into command mode

1 – start range
2 – end range
s – substitution

” – the character that needs to be retraced. remember , whenever we are using a special character we need to precede it with back slash

now the file looks like

apple
mango
orange

hence the general pattern Will be

 
:start,end s/text to find/text to replace

another simple example

 
:s1,10/a/b
Advertisements

Comments are closed.