I have done it with simple loop to count and print through.. How can I do it in bash scripting with program such as sed,awk ?
2 Answers
Something like this:
awk 'NR % 3 == 2'
Test
sh-3.2$ more test 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Result
sh-3.2$ awk 'NR % 3 == 2' < test
2
5
8
11
14
-
1
-
You can do it like this with GNU sed:
seq 20 | sed -n '2~3p'
Output:
2
5
8
11
14
17
20