34.7 Delimiting a Regular Expression
Whether in
sed
or
vi
, when using the substitution
command, a delimiter is required to separate the search pattern
from the replacement string. The delimiter can be any character except
blank or a newline (
vi
seems to be more restrictive than
sed
), although the usual
practice is to use the slash ( When either the search pattern or the replacement string contains a slash, it is easier to change the delimiter character rather than escape the slash. Thus, if the pattern was attempting to match UNIX pathnames, which contain slashes, you could choose another character, such as a colon, as the delimiter:
s:/usr/mail:/usr2/mail:
Note that the delimiter appears three times and
is required after the
replacement
.
Regardless of which delimiter you use, if it does appear in the
regular expression, use a backslash ( If you don't know what characters the search pattern might have (in a shell program that handles any kind of input, for instance), the safest choice for the delimiter can be a control character. Article 45.35 shows how to make and use a control character as the delimiter in a shell script - without having to store the control character in the file.
You can use any delimiter for a pattern address (not just a slash).
Put a backslash (
\:/usr/mail:d - , |
|