vi Global Replacement
Linux Commands - Shells

The ex editor checks each line for a specific pattern.  Once it finds the pattern it will replace it with the new string of characters.  Global replacement uses two ex commands:
:g    (global)
:s    (substitute)


The substitute command in this example is used to substitute “oldtext” with the “newtext” in the first occurrence of the line.


The / is a delimiter between the oldtext and newtext.

If you wanted to change every occurrence of oldtext in the line you would use this command:


You can extend the range of lines to change the oldtext to newtext with a range of page addresses.  The example changes every instance of oldtext to newtext from lines 25 to line 175.


If you wanted to change every instance in the entire file you could use either one of these commands.