Go to the first, previous, next, last section, table of contents.
If you use SED at all, you will quite likely want to know these commands.
#
"command" begins a comment;
the comment continues until the next newline.
If you are concerned about portability, be aware that
some implementations of SED (which are not POSIX.2
conformant) may only support a single one-line comment,
and then only when the very first character of the script is a #
.
Warning: if the first two characters of the SED script
are #n
, then the -n
(no-autoprint) option is forced.
If you want to put a comment in the first line of your script
and that comment begins with the letter `n'
and you do not want this behavior,
then be sure to either use a capital `N',
or place at least one space before the `n'.
/
characters may be uniformly replaced by
any other single character within any given s
command.)
The /
character (or whatever other character is used in its stead)
can appear in the regexp or replacement
only if it is preceded by a \
character.
Also newlines may appear in the regexp using the two
character sequence \n
.
The s
command attempts to match the pattern
space against the supplied regexp.
If the match is successful, then that portion of the pattern
space which was matched is replaced with replacement.
The replacement can contain \n
(n being
a number from 1 to 9, inclusive) references, which refer to
the portion of the match which is contained between the nth
\(
and its matching \)
.
Also, the replacement can contain unescaped &
characters which will reference the whole matched portion
of the pattern space.
To include a literal \
, &
, or newline in the final
replacement, be sure to precede the desired \
, &
,
or newline in the replacement with a \
.
The s
command can be followed with zero or more of the
following flags:
-n
command-line option.
Note: some implementations of SED, such as this one, will
double-print lines when auto-print is not disabled and the p
command is given.
Other implementations will only print the line once.
Both ways conform with the POSIX.2 standard, and so neither
way can be considered to be in error.
Portable SED scripts should thus avoid relying on either behavior;
either use the -n
option and explicitly print what you want,
or avoid use of the p
command (and also the p
flag to the
s
command).
{
and }
characters.
(The }
must appear in a zero-address command context.)
This is particularly useful when you want a group of commands
to be triggered by a single address (or address-range) match.
Go to the first, previous, next, last section, table of contents.