
i | 763
sed
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Example
This script collects all lines containing the word Item: and moves
them after a place marker later in the file. The original
Item: lines
are deleted.
/Item:/{
H
d
}
/Summary of items:/G
h
[address1[,address2]]h
Copy the pattern space into the hold space, a special temporary
buffer. The previous contents of the hold space are obliterated. You
can use h to save a line before editing it.
Example
# Edit a line; print the change; replay the original
/Linux/{
h
s/.* Linux \(.*\) .*/\1:/
p
x
}
Sample input:
This describes the Linux ls command.
This describes the Linux cp command.
Sample output:
ls:
This describes the Linux ls command.
cp:
This describes the Linux cp command.
H
[address1[,address2]]H
Append a newline and then the contents of the pattern space to the
contents of the hold space. Even if the hold space is empty, H still
appends a newline. H is like an incremental copy. See Examples
under g and G.
i
[address]i\
text
[address1[,address2]]i \ {G}
text
Insert text before each line matched by address. (See a for details on
text.)
The GNU version accepts two addresses and allows you to put the
first line of text on the same line as the i command.