Home / Blog

To find and replace one or more occurences of a given text pattern with a new text string, use the s[ubstitute] command.

First we need to do is to open the file we want to do the "search and replace"

qkim@lotta:~> vim file.txt

This is the content of file.txt. Lets change some of it with search and replace.
This is a test, a test this is. Just a lots of tests. I want to change test with beer.

:%s/test/beer/g
4 substitutions on 1 line
:wq

qkim@lotta:~> cat file.txt
This is the content of file.txt. Lets change some of it with search and replace.
This is a beer, a beer this is. Just a lots of beers. I want to change beer with beer.

my blog

Mon Tue Wed Thu Fri Sat Sun
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30