4

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 2

7

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
2
  • 1
    awk 'NR % 3 == 2' is a much simpler expression. Apr 24, 2013 at 1:26
  • done @glennjackman :=)
    – Rinzwind
    Apr 24, 2013 at 6:29
5

You can do it like this with GNU sed:

seq 20 | sed -n '2~3p'

Output:

2
5
8
11
14
17
20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .