HP-UX Reference (11i v2 04/09) - 1 User Commands A-M (vol 1)

e
ed(1) ed(1)
s/s1/s2 g/s1 ?s1
s/s1/s2/p g/s1/p ?s1?
Line Addresses
To understand line addressing, remember that
ed
maintains a pointer to the current line. Generally
speaking, the current line is the last line affected by a command. The exact effect of a given command on
the current line is discussed under the description of each command. Addresses are interpreted accord-
ing to the following rules:
1. The character
. refers to the current line.
2. The character
$ refers to the last line of the buffer.
3. A decimal number n refers to the nth line of the buffer.
4. A
x refers to the line marked with the mark name character x, which must be a lower-case
letter. Lines are marked with the
k command described below.
5. An RE enclosed by slashes (
/RE/) refers to the first line found by searching forward from the
line following the current line toward the end of the buffer and stopping at the first line contain-
ing a string matching the RE. If necessary, the search wraps around to the beginning of the
buffer and continues up to and including the current line, so that the entire buffer is searched.
(Also see WARNINGS below.)
6. An RE enclosed by question marks (
?RE?) addresses the first line found by searching back-
ward from the line preceding the current line toward the beginning of the buffer and stopping at
the first line containing a string matching the RE. If necessary, the search wraps around to the
end of the buffer and continues up to and including the current line. (Also see WARNINGS
below.)
7. An address followed by a plus (
+) or minus (-
) sign followed by a decimal number specifies that
address plus or minus the indicated number of lines. The plus sign can be omitted.
8. If an address begins with
+ or -, the addition or subtraction is calculated with respect to the
current line. For example, -5 is interpreted as .-5.
9. If an address ends with
+ or -, 1 is added to or subtracted from the address, respectively. As a
consequence of this and rule 8 above, the address - refers to the line preceding the current line.
(To maintain compatibility with earlier versions of the editor, the circumflex (
ˆ) and - charac-
ters are interpreted identically when encountered in addresses.) Moreover, multiple trailing
+
and - characters have a cumulative effect, so -- refers to the second line preceding the current
line.
10. For convenience, a comma (
,) represents the address pair
1,$, while a semicolon (;)
represents the pair
.,$.
Commands require zero, one, or two addresses. Commands that do not use addresses treat the presence
of an address as an error. Commands that accept one or two addresses assume default addresses when
the number of addresses specified is insufficient. If more addresses are specified than a given command
requires, the last one or two are used as appropriate.
Addresses are usually separated from each other by a comma (
,). They can also be separated by a semi-
colon (;), in which case the current line (.) is set to the first address, after which the second address is
calculated. This feature can be used to determine the starting line for forward and backward searches
(see rules 5 and 6 above). The second address of any two-address sequence must correspond to a line in
the buffer that follows the line corresponding to the first address.
Editor Commands
In the following list of
ed commands, the default addresses are shown in parentheses (parentheses are
not part of the address and should not be placed in an actual command except for other purposes).
It is generally illegal for more than one command to appear on a line. However, any command (except
e,
f, r,orw) can be suffixed by l, n,orp in which case the current line is respectively either listed, num-
bered, or printed, as discussed below under the l, n, and p commands.
(
.)a
text
.
The a (append) command reads text and appends it after the addressed line. Upon com-
pletion, the new current line is the last inserted line, or, if no text was added, at the
addressed line. Address 0 is legal for this command, causing the appended text to be
placed at the beginning of the buffer.
Section 1220 Hewlett-Packard Company 2 HP-UX 11i Version 2: September 2004