Skip to Content
Linux in a Nutshell, 6th Edition
book

Linux in a Nutshell, 6th Edition

by Ellen Siever, Stephen Figgins, Robert Love, Arnold Robbins
September 2009
Beginner
942 pages
85h 34m
English
O'Reilly Media, Inc.
Content preview from Linux in a Nutshell, 6th Edition

Pattern Addressing

A sed command can specify zero, one, or two addresses. In POSIX sed, an address has one of the forms in the following table. Regular expressions are described in Chapter 7. Additionally, \n can be used to match any newline in the pattern space (resulting from the N command), but not the newline at the end of the pattern space.

Address

Meaning

/pattern/

Lines that match pattern.

\pattern;

Like previous, but use semicolon as the delimiter instead of slash. Any character may be used. This is useful if pattern contains multiple slash characters.

n

Line number n.

$

The last input line.

If the command specifies:

Then the command is applied to:

No address

Each input line.

One address

Any line matching the address. Some commands accept only one address: a, i, r, q, and =.

Two comma-separated addresses

First matching line and all succeeding lines up to and including a line matching the second address.

An address followed by !

All lines that do not match the address.

GNU sed allows additional address forms:

Address

Meaning

/pattern/i

Match pattern, ignoring case. I may be used instead of i.

/pattern/m

Match pattern, allowing ^ and $ to match around an embedded newline. M may be used instead of m.

0,/pattern/

Similar to 1,/pattern/, but if line 1 matches pattern, it will end the range.

address,+n

Matches line matching address, and the n following lines.

address~incr

Matches line matching address and every incr lines after it. For example, 42˜3 matches 42, 45, 48, and so on.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Unix in a Nutshell, 4th Edition

Unix in a Nutshell, 4th Edition

Arnold Robbins
Linux Under the Hood

Linux Under the Hood

Sander van Vugt
Linux Kernel in a Nutshell

Linux Kernel in a Nutshell

Greg Kroah-Hartman

Publisher Resources

ISBN: 9780596806088Errata Page