For learning pattern matching, we will ensure that the pattern that we will search should be highlighted when the searched pattern is found.
The configuration file for vi is /etc/vimrc.
In the vi editor, give the following command to highlight search:
|
Sr. |
Commands |
Description |
|---|---|---|
|
1 |
|
This highlights search pattern |
|
2 |
|
Show when you are in insert mode |
|
3 |
|
Ignore case when searching |
|
4 |
|
Shows case sensitive search |
The mentioned user should open the file in vi, press the Esc button so that it goes into command mode and then enter colon followed by these commands.
The following are commands for pattern search and replace:
The following is an example of regular expression for replacing Tom by David:
:1,$s/tom/David/g // from line 1 to end ($), replace tom by David :1,$s/\<[tT]om\>/David/g // start and end of word \< \>
This is another example of regular expression.
Create the love.txt file, as follows:
Man has love for Art World is full of love Love makes world wonderful love looove lve love Love love lover loves I like "Unix" more than DOS I love "Unix"/ I said I love "Unix" I love "unix" a lot
Use the following commands for testing pattern searching facilities: