1. What is the difference between s/old/new/ and s/old/new/g ?
The g option at the end of the line will replace all occurrences of “old” in a particular line with “new”.
If the g option is not used only the first occurrence of “old” in a particular line will be replaced with “new”.
2. What is the use of the “c” option in the use caseĀ s/old/new/gc ?
This option will ask for an affirmation or negation before every replacement is made.
3. What does this mean :g/some text/s/search text/replacement text/ ?
“for all lines containing `some text’, search for `search text’ and replace any instances with `replacement text.'”
4. What does this mean :g!/some text/s/search text/replacement text/ ?
“for all lines not containing `some text’, search for `search text’ and replace any instances with `replacement text.'”
It is the same as :v/some text/s/search text/replacement text/
Reference :
http://sunsite.uakom.sk/sunworldonline/swol-10-1997/swol-10-unix101.html