ed: Line addressing
4 Line addressing
*****************
An address represents the number of a line in the buffer. 'ed' maintains a
"current address" which is typically supplied to commands as the default
address when none is specified. When a file is first read, the current
address is set to the address of the last line of the file. In general, the
current address is set to the address of the last line affected by a
command.
One exception to the rule that addresses represent line numbers is the
address '0' (zero). This means "at the beginning of the buffer", and is
valid wherever it makes sense.
An address range is two addresses separated either by a comma (',') or a
semicolon (';'). In a semicolon-delimited range, the current address ('.')
is set to the first address before the second address is calculated. This
feature can be used to set the starting line for searches if the second
address contains a regular expression. The value of the first address in a
range cannot exceed the value of the second.
Addresses can be omitted on either side of the comma or semicolon
separator. If only the first address is given in a range, then the second
address is set to the given address. If only the second address is given,
the resulting address pairs are '1,addr' and '.;addr' respectively. If a
N-tuple of addresses is given where N > 2, then the corresponding range is
determined by the last two addresses in the N-tuple. If only one address is
expected, then the last address is used. It is an error to give any number
of addresses to a command that requires zero addresses.
A line address is constructed as follows:
'.'
The current line (address) in the buffer.
'$'
The last line in the buffer.
'N'
The Nth line in the buffer, where N is a number in the range '0,$'.
'+N'
The Nth next line, where N is a non-negative number.
'-N'
The Nth previous line, where N is a non-negative number.
'+'
The next line. This is equivalent to '+1' and may be repeated with
cumulative effect.
'-'
The previous line. This is equivalent to '-1' and may be repeated with
cumulative effect.
','
The first through last lines in the buffer. This is equivalent to the
address range '1,$'.
';'
The current through last lines in the buffer. This is equivalent to the
address range '.;$'.
'/RE/[I]'
The next line containing the regular expression RE. The search wraps
to the beginning of the buffer and continues down to the current line,
if necessary. The suffix 'I' is a GNU extension which makes 'ed' match
RE in a case-insensitive manner.
'?RE?[I]'
The previous line containing the regular expression RE. The search
wraps to the end of the buffer and continues up to the current line, if
necessary. The suffix 'I' is a GNU extension which makes 'ed' match RE
in a case-insensitive manner.
''x'
The apostrophe-x character pair addresses the line previously marked by
a 'k' (mark) command, where 'x' is a lower case letter from the
portable character set '[a-z]'.
Addresses can be followed by one or more address offsets, optionally
separated by whitespace. Offsets are constructed as follows:
* '+' or '-' followed by a number adds or subtracts the indicated number
of lines to or from the address.
* '+' or '-' not followed by a number adds or subtracts 1 to or from the
address.
* A number adds the indicated number of lines to the address.
It is not an error if an intermediate address value is negative or
greater than the address of the last line in the buffer. It is an error if
the final address value is negative or greater than the address of the last
line in the buffer. It is an error if a search for a regular expression
fails to find a matching line.