You're viewing a comment by Paul and its responses.

Paul Permalink
July 29, 2009, 16:46

Serious error in #45, #46 and many others.
FNR is the line number in the *current* file.
NR is the cumulative line number across all inputs.

awk 'code' six_lines.txt ten_lines.txt will have
NR == 1 and FNR == 1
NR == 7 and FNR == 1 again
and END will see NR == 16 and FNR == 10.

Programs that check for change in FILENAME would be more efficient to check for FNR == 1.

Awk to print first 10 lines of several files:

awk 'FNR == 1 { print "\n.... " FILENAME; } FNR < 11

If your awk has "nextfile" it saves reading lines after first 10.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the word "security": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.