awk comparing two files problem



Hello,

I got this code from one the the groups. Can somebody explain me what
exactly is happening here and how is that happening? Please provide a
detail explation. I am not good at awk when more than one files are
involved.
------------------------------------------------------------------------------------------------------
you want all the lines in file1 that are not in file2,
awk 'NR == FNR { a[$0]; next } !($0 in a)' file2 file1

If you want only uniq lines in file1 that are not in file2,
awk 'NR == FNR { a[$0]; next } !($0 in a) { print; a[$0] }'
file2
file1

---------------------------------------------------------------------------------------------------------

-RB

.



Relevant Pages

  • Re: Query in Sort
    ... If File1 has the following records ... File2 only DDD ... send email to listserv@xxxxxxxxxxx with the message: GET IBM-MAIN INFO ... Search the archives at http://bama.ua.edu/archives/ibm-main.html ...
    (bit.listserv.ibm-main)
  • Re: Query in Sort
    ... If File1 has the following records ... File2 only DDD ... send email to listserv@xxxxxxxxxxx with the message: GET IBM-MAIN INFO ... Search the archives at http://bama.ua.edu/archives/ibm-main.html ...
    (bit.listserv.ibm-main)
  • Re: Query in Sort
    ... The Two file match in EZT assumes the files are sorted in desired sequence ... If File1 has the following records ... File2 only DDD ... segments also needs to be written in out file. ...
    (bit.listserv.ibm-main)
  • Re: simple ln question
    ... that makes it so the contents of file1 are the same as of file2, and if you change the contents of 1, the other ... prints the inode number for the file foobar. ...
    (Fedora)
  • RE: data conundrum
    ... in your spens you'll want to keep field names consistent. ... the specs will be the most tedious, but once theyr're done once they're done. ... in other words, you have file1, file2, file3..... ...
    (microsoft.public.access.externaldata)