The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 05-26-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,346
Quote:
Originally Posted by paul.o View Post
Yes, nawk worked, thank you very much. I was wondering, if you didn't mind, if you could breakdown the script so I can understand exactly how it's working? I'd like to learn as much of this as I can. Thanks.

Code:
awk -F, 'NR==FNR && /^D/ {a[$2]++;next}
$9 in a || $10 in a {print "D," $1}' file1 file2

Here we go:


Code:
awk -F,

Set field separator


Code:
NR==FNR && /^D/

If we read the 1st file and the line starts with a "D"


Code:
{a[$2]++;next}

Set array a with the 2nd field as index and read the next line


Code:
$9 in a || $10 in a {print "D," $1}'

If the 9th or the 10th field exists as an index of the array a in the 2nd file print "D," and the 1st field.


Regards