
Q | 765
sed
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
p
[address1[,address2]]p
Print the addressed line(s). Note that this can result in duplicate
output unless default output is suppressed by using #n or the -n
command-line option. Typically used before commands that
change control flow (d, n, b), which might prevent the current line
from being output. See the Examples under h, n, and N.
P
[address1[,address2]]P
Print first part (up to embedded newline) of multiline pattern space
created by N command. Same as p if N has not been applied to a
line.
Example
Suppose you have function references in two formats:
function(arg1, arg2)
function(arg1,
arg2)
The following script changes argument arg2, regardless of whether
it appears on the same line as the function name:
s/function(arg1, arg2)/function(arg1, XX)/
/function(/{
N
s/arg2/XX/
P
D
}
q
[address]q
[address]q [value] {G}
Quit when address is encountered. The addressed line is first
written to the output (if default output is not suppressed), along
with any text appended to it by previous a or r commands. GNU
sed allows you to provide value, which is used as the exit status.
Examples
Delete everything after the addressed line:
/Garbled text follows:/q
Print only the first 50 lines of a file:
50q
Q
[address]Q [value] {G}
Quits processing, but without printing the pattern space. If value is
provided, it ...