I know this is a stupid question, but it doesn't work.
I have a file with 10 lines and I want to pipe the content to awk and then print line 1 til 2 into another file and then line 3-4 ...
yes, thats the problem, but a normal variable in a for-loop cannot adress the NR. Or better to say: I don't know how.
But how can I control from line 2 til line 4 do print with one of these solutions? (In reality the file consists 70 million lines and I have to seperate it into 600000 lines per new file)
Because the nawk-version is writing only writing one line into one file...
I didn't test it, but I don't think you can. It looks to me like that code ony works for FNR%n when n==2, since the result toggles between 1,0,1,0,1,0..., incrementing f as needed. If n==1, FNR%n==0 for all FNR and f always remains 0. When n>2, f will increment on each line read except when FNR%n==0, and the increments will be in steps of f+=1, f+=2, f+=3... f+=(n-1), f+=0, f+=1... creating a discontinous, ever increasing series.
Regards,
Alister
---------- Post updated at 07:50 PM ---------- Previous update was at 07:45 PM ----------
Of course, you can accomodate any n with a slight tweak to the code (initialize f to 1 and only increment f when FNR%n==0). If that's what you meant, disregard the noise.