sed: Numeric Addresses
4.2 Selecting lines by numbers
==============================
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
unless '-i' or '-s' options are specified.)
'$'
This address matches the last line of the last file of input, or
the last line of each file when the '-i' or '-s' options are
specified.
'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, one would use '1~2' to select the odd-numbered
lines and '0~2' for even-numbered lines; 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'.
The following commands demonstrate the step address usage:
$ seq 10 | sed -n '0~4p'
4
8
$ seq 10 | sed -n '1~3p'
1
4
7
10