So [tt]NR[/tt] counts the lines from the very begining countinuously until the end. [tt]FNR[/tt] restarts the counting at the begining of each input file.
So the [tt]NR==FNR[/tt] expression evaluate to true only while the first input file is parsed.
NR is the Number of the current Record (line) being processed.
FNR is the Number of the current Record within the current file.
So, for the first file processed they will be equal but on the first line of the second and subsequent files FNR will start from 1 again.
In the example code, when NR==FNR (i.e. when processing the first file) an associative array is built up storing the first field in an array element which also has the first field as its index.
next means nothing else is done with this line from the first file.
when NR!=FNR (i.e. when processing the second and subsequent files) the associative array is checked to see if it has an element indexed by the first field and if so the default behaviour (of printing out all of the line being processed) is carried out.
==========================================
Some cause happiness wherever they go; others whenever they go.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.