print selected rows with awk

Hi everybody:

Could anybody tell me how I can print from a file a selected rows with awk. In my case I only want print in another file all the rows from NR=8 to NR=2459 and the increment each 8 times.

I tried to this:

awk '{for (i=8; i=2459; i+=8); NR==i}' file1 > file2

But doesn't work.
Thanks in advance. :cool:

awk 'NR%8==0 && NR<=2459' file

Not sure to understand the request, but may be:

awk 'NR==8,NR==2459{for(i=1;i<9;i++)print}' filename

Thanks for your reply, but with your help I print all rows from NR=8 to NR<=2459. And I would like that print it with an 8 increment. :confused:

Thanks radoulov I tried your reply:

awk 'NR==8,NR==2459{for(i=1;i<9;i++)print}' filename

but the result is not as I like. Actually I would like that it prints only the rows with NR=8, 15, 22, 29 .... until 2459. :rolleyes:

awk 'NR==8,NR==2459{if(NR%7==1)print}' filename

Use nawk or /usr/xpg4/bin/awk on Solaris.

Thanks a lot, now it works correctly. :b::smiley: