For changing text or correcting spelling errors, use the
s (substitute)
subcommand. When you enter the subcommand, the line you are changing
becomes your current working line. To display the line after you
make the change, enter the
p (print) subcommand.
- To substitute text for the first matching string on the current
working line, enter:
s/oldtext/newtext/
- To substitute text for the first matching string on a specified
line, enter:
ns/oldtext/newtext/
where n is the number of the line.
- To substitute text for the first matching string on more than
one line, enter:
a1,a2s/oldtext/newtext/
where a1 is the number (or address) of the first line to be changed
and a2 is the number of the last line to be changed.
- To change every occurrence of a string on more than one line,
enter:
a1,a2s/oldtext/newtext/g
where a1 is the number of the first line to be changed and a2 is
the number of the last line to be changed. g is the global
operator.
To change every occurrence of a string on one line, enter:
ns/oldtext/newtext/g
g is the
global operator.
- To delete a word or string, enter:
s/oldtext//