Andrea Francia - 1 year ago 35
Bash Question

How to write a unix filter that outputs only a line every N lines

Suppose to feed the filter standard input with these line:

line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10


It would be nicer if someone tell me how to write a script that prints only every 4 lines, in the case of the example input above:

line 1
line 5
line 9


\$ yes | cat -n | head -10 | awk 'NR % 4 == 1'

That is, your answer is "awk 'NR % 4 == 1'".