to the second address. Three
things to note about address ranges: the syntax is addr1,addr2 (i.e.,
the addresses are separated by a comma); the line which addr1 matched
will always be accepted, even if addr2 selects an earlier line; and if
addr2 is a regexp, it will not be tested against the line that addr1
matched.
After the address (or address‐range), and before the command, a ! may
be inserted, which specifies that the command shall only be executed if
the address (or address‐range) does not match.
The following address types are supported:
number Match only the specified line number (which increments cumula‐
tively across files, unless the -s option is specified on the
command line).
first~step
Match every step’th line starting with line first. For example,
‘‘sed -n 1~2p’’ will print all the odd‐numbered lines in the in‐
put stream, and the address 2~5 will match every fifth line,
starting with the second. first can be zero; in this case, sed
operates as if it were equal to step. (This is an extension.)
$ Match the last line.
/regexp/
Match lines matching the regular expression regexp. Matching is
performed on the current pattern space, which can be modified
with commands such as ‘‘s///’’.
\cregexpc
Match lines matching the regular expression regexp. The c may be
any character.
GNU sed also supports some special 2‐address forms:
0,addr2
Start out in "matched first address" state, until addr2 is found.
This is similar to 1,addr2, except that if addr2 matches the very
first line of input the 0,addr2 form will be at the end of its
range, whereas the 1,addr2 form will still be at the beginning of
its range. This works only when addr2 is a regular expression.
addr1,+N
Will match addr1 and the N lines following addr1.
addr1,~N
Will match addr1 and the lines following addr1 until the next
line whose input line number is a multiple of N.
REGULAR EXPRESSIONS
POSIX.2 BREs should be supported, but they aren’t completely because of
performance problems. The \n sequence in a regular expression matches
the newline character, and similarly for \a, \t, and other sequences.
The ‐E option switches to using extended regular expressions instead; it
has been supported for years by GNU sed, and is now included in POSIX.
BUGS
E‐mail bug reports to bug‐sed@gnu.org. Also, please include the output
of ‘‘sed --version’’ in the body of your report if at all possible.
AUTHOR
Written by Jay Fenlason, Tom Lord, Ken Pizzini, Paolo Bonzini, Jim Mey‐
ering, and Assaf Gordon.
This sed program was built with SELinux support. SELinux is disabled on
this system.
GNU sed home page: <https://www.gnu.org/software/sed/>. General help
using GNU software: <https://www.gnu.org/gethelp/>. E-mail bug reports
to: <bug-sed@gnu.org>.
SEE ALSO
awk(1), ed(1), grep(1), tr(1), perlre(1), sed.info, any of various books
on sed, the sed FAQ (http://sed.sf.net/grabbag/tutorials/sedfaq.txt),
http://sed.sf.net/grabbag/.
The full documentation for sed is maintained as a Texinfo manual. If
the info and sed programs are properly installed at your site, the com‐
mand
info sed
should give you access to the complete manual.
GNU sed 4.9 January 2023 SED(1)