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 according 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 ®rst line found by searching forward from the line following the current line toward the end of the buffer and stopping at the ®rst line containing 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 ®rst line found by searching backward from the line preceding the current line toward the beginning of the buffer and stopping at the ®rst 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 speci®es 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, -5is 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 circum¯ex (Ã) and - characters 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 speci®ed is insuf®cient. If more addresses are speci®ed 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 semicolon (;), in which case the current line (.) is set to the ®rst address, after which the second address is cal- culated. 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 ®rst 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, or w) can be suf®xed by l, n, or p 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

The a (append) command reads text and appends it after the addressed line. Upon comple-

text

tion, 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 1196

− 2 −

HP-UX Release 11i: December 2000