I have a large file.

How can I print every 9th line starting at line 6?

awk NR % 9 == 0' file1 > file2

In GNU sed you can use the first~step operator:

sed -n '6~9p' file1 > file2

Use a variable (lin) which holds the line number, from line 6. If lin is a multiple of 9 then print the line with the line number.

awk '{lin=NR-6; if (!(lin %9)) print}' file1 > file2

Your Answer

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