Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Would any body explain me pieces in following awk ?

Status
Not open for further replies.

netbackup1234

Programmer
Aug 27, 2006
24
US
Hi
I got following from somebody and trying to understand..
awk 'NR==FNR{a[$0];next}{if ($0 in a) {print $0}}' cbdnode1 cbdnode2

specialy NR==FNR{a[$0];next}

Thank you
 
NR==FNR{a[$0];next}
Populate the a array while reading the first file.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
NR is the record number currently being processed overall.

FNR is the record number currently being processed within the current file.

So they will only be equal while it is processing the first input file.

Annihilannic.
 
Thank you Annililannic
I see this( 'NR==FNR{a[$0];next}) part of awk handles cbdnode1 file and other part ( {if ($0 in a) {print $0}}') handles cbdnode2 file.
By the way what happens if there are more than 2 input files to process ?
 
The first part would be use handle the first file, and the second part would handle all of the rest of the input files.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top