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