system
September 27, 2007, 3:43am
1
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.
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
system
September 27, 2007, 5:26am
4
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.
system
September 27, 2007, 5:39am
5
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.
system
September 27, 2007, 6:23am
7
Thanks a lot, now it works correctly.