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 ?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.