Selecting lines with sed
number
first
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 $ - last line
Read full article from Addresses - sed, a stream editor
number
~step1~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’/regexp/
0,/regexp/
- addr1
,+N
- Matches addr1 and the N lines following addr1.
- addr1
,~N
- Matches addr1 and the lines following addr1 until the next line whose input line number is a multiple of N.
Appending the ! character to the end of an address specification negates 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.
No comments:
Post a Comment