sed: Numeric Addresses
1
1 4.2 Selecting lines by numbers
1 ==============================
1
1 Addresses in a 'sed' script can be in any of the following forms:
1 'NUMBER'
1 Specifying a line number will match only that line in the input.
1 (Note that 'sed' counts lines continuously across all input files
1 unless '-i' or '-s' options are specified.)
1
1 '$'
1 This address matches the last line of the last file of input, or
1 the last line of each file when the '-i' or '-s' options are
1 specified.
1
1 'FIRST~STEP'
1 This GNU extension matches every STEPth line starting with line
1 FIRST. In particular, lines will be selected when there exists a
1 non-negative N such that the current line-number equals FIRST + (N
1 * STEP). Thus, one would use '1~2' to select the odd-numbered
1 lines and '0~2' for even-numbered lines; to pick every third line
1 starting with the second, '2~3' would be used; to pick every fifth
1 line starting with the tenth, use '10~5'; and '50~0' is just an
1 obscure way of saying '50'.
1
1 The following commands demonstrate the step address usage:
1
1 $ seq 10 | sed -n '0~4p'
1 4
1 8
1
1 $ seq 10 | sed -n '1~3p'
1 1
1 4
1 7
1 10
1