Linux Shell Scripting Tutorial (LSST) v1.05r3
Chapter 6: Learning expressions with ex

Searching the words

(a) Give following command
:/linux/ p
I love linux.

Note In ex you can specify address (line) using number for various operation. This is useful if you know the line number in advance, but if you don't know line number, then you can use contextual address to print line on-screen. In above example /linux/ is contextual address which is constructed by surrounding a regular expression with two slashes. And p is print command of ex.
Try following and not down difference (Hint - Watch p is missing)

(b)Give following command
:g/linux/ p

I love linux.
My brother Vikrant also loves linux.

He currently lerarns linux.
Next year linux will be 11 year old.

. (DOT) is special command of linux.

In previous example (:/linux/ p) only one line is printed. If you want to print all occurrence of the word "linux" then you have to use g, which mean global line address. This instruct ex to find all occurrence of pattern. Try following
:1,$ /Linux/ p

Which give the same result. It means g stands for 1,$.

Saving the file in ex

Give command
"demofile" 20L, 386C written

w command will save the file.

Quitting the ex

Give command

q command quits from ex and you are return to shell prompt.

Note use wq command to do save and exit from ex.

Coping lines
Find and Replace (Substituting regular expression)