Print every nth line

Dear all,

How to print every nth line. File like this:

File input:
1
1
1
1
1
1
2
2
2
3
3
3
3
3
3
4
4
4

Desire output:

1
1
2
3
3
4

For this example, I must print 3rd, 6th, 9th, 12th, 15th, 18th line (every 3 line).

Thanks for advance.

Attila

Try this:

awk 'NR % 3 == 0'  input-file >output-file

Should print as you want.

1 Like
 
cat filename.txt | xargs -n3 | awk '{print $NF}'
 

Thank agama, it work