Copyright (C) 2000-2012 |
GNU Info (sed.info)AddressesSelecting lines with SED ======================== Addresses in a SED script can be in any of the following forms: `NUMBER' Specifying a line number will match only that line in the input. (Note that SED counts lines continuously across all input files.) `FIRST~STEP' This GNU extension matches every STEPth line starting with line FIRST. In particular, lines will be selected when there exists a non-negative N such that the current line-number equals FIRST + (N * STEP). Thus, to select the odd-numbered lines, one would use `1~2'; to pick every third line starting with the second, `2~3' would be used; to pick every fifth line starting with the tenth, use `10~5'; and `50~0' is just an obscure way of saying `50'. `$' This address matches the last line of the last file of input. `/REGEXP/' This will select any line which matches the regular expression REGEXP. If REGEXP itself includes any `/' characters, each must be escaped by a backslash (`\'). `\%REGEXP%' (The `%' may be replaced by any other single character.) This also matches the regular expression REGEXP, but allows one to use a different delimiter than `/'. This is particularly useful if the REGEXP itself contains a lot of `/'s, since it avoids the tedious escaping of every `/'. If REGEXP itself includes any delimiter characters, each must be escaped by a backslash (`\'). `/REGEXP/I' `\%REGEXP%I' The `I' modifier to regular-expression matching is a GNU extension which causes the REGEXP to be matched in a case-insensitive manner. If no addresses are given, then all lines are matched; if one address is given, then only lines matching that address are matched. An address range can be specified by specifying two addresses separated by a comma (`,'). An address range matches lines starting from where the first address matches, and continues until the second address matches (inclusively). If the second address is a REGEXP, then checking for the ending match will start with the line _following_ the line which matched the first address. If the second address is a NUMBER less than (or equal to) the line matching the first address, then only the one line is matched. Appending the `!' character to the end of an address specification will negate the sense of the match. That is, if the `!' character follows an address range, then only lines which do _not_ match the address range will be selected. This also works for singleton addresses, and, perhaps perversely, for the null address. automatically generated by info2www version 1.2.2.9 |