Linux Shell Scripting Tutorial (LSST) v1.05r3 | ||
Chapter 6: Learning expressions with ex | ||
|
Will find word like theater, the, brother, other etc. What if you want to just find the word like "the" ? To find the word (Let's say Linux) you can give command like
:/\<Linux\>
Linux is cooool.
:g/\<Linux\>/p
Linux is cooool.
Linux is now 10 years old.
Rani my sister never uses Linux
The symbol \< and \> respectively match the empty string at the beginning and end of the word. To find the line which contain Linux pattern at the beginning give command
:/^Linux
Linux is cooool.
As you know $ is end of line character, the ^ (caret) match beginning of line. To find all occurrence of pattern "Linux" at the beginning of line give command
:g/^Linux
Linux is cooool.
Linux is now 10 years old.
And if you want to find "Linux" at the end of line then give command
:/Linux $
Rani my sister never uses Linux
Following command will find empty line:
:/^$
To find all blank line give command:
:g/^$
To view entire file without blank line you can use command as follows:
:g/[^/^$]
Hello World.
This is vivek from Poona.
I love linux.
It is different from all other Os
My brother Vikrant also loves linux who also loves unix.
He currently learn linux.
Linux is cooool.
Linux is now 10 years old.
Next year linux will be 11 year old.
Rani my sister never uses Linux
She only loves to play games and nothing else.
Do you know?
. (DOT) is special command of linux.
Okay! I will stop.
Command | Explanation |
g | All occurrence |
/[^ | [^] This means not |
/^$ | Empty line, Combination of ^ and $. |
To delete all blank line you can give command as follows
:g/^$/d
Okay! I will stop.
:1,$ p
Hello World.
This is vivek from Poona.
I love linux.
It is different from all other Os
My brother Vikrant also loves linux who also loves unix.
He currently learn linux.
Linux is cooool.
Linux is now 10 years old.
Next year linux will be 11 year old.
Rani my sister never uses Linux
She only loves to play games and nothing else.
Do you know?
. (DOT) is special command of linux.
Okay! I will stop.
Try u command to undo, to undo what you have done it, give it as follows:
:u
:1,$ p
Hello World.
This is vivek from Poona.
....
...
....
Okay! I will stop.
Replacing word with confirmation from user | Using range of characters in regular expressions |