![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Awk: different between NR and FNR
As I know:
FNR: The ordinal number of the current record in the current file. NR: The ordinal number of the current record from the start of input. I don't understand really differency between NR and FNR. Who can explain it for me? And give me an example. Thanks |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
f1:
Code:
a b c d Code:
e f g Code:
awk '{printf("file->[%s] NR->[%d] FNR->[%d] str->[%s]\n", FILENAME, NR, FNR, $0)}' f1 f2
Code:
file->[f1] NR->[1] FNR->[1] str->[a] file->[f1] NR->[2] FNR->[2] str->[b] file->[f1] NR->[3] FNR->[3] str->[c] file->[f1] NR->[4] FNR->[4] str->[d] file->[f2] NR->[5] FNR->[1] str->[e] file->[f2] NR->[6] FNR->[2] str->[f] file->[f2] NR->[7] FNR->[3] str->[g] |
||||
| Google The UNIX and Linux Forums |