Re: Help -- how to get the difference of these two files



2007-02-11, 19:04(-08), jzhang2006@xxxxxxxxx:
I have two files:

file1 --
"John" "Hello" "World" "AE" "01-2007"
"John2" "Hello2" "World2" "AE2" "01-2007"
"John3" "Hello3" "World" "AE3" "01-2007"
"John4" "Hello4" "World4" "AE4" "01-2007"
"John5" "Hello5" "World5" "AE5" "01-2007"

file2 --
"John" "Hello" "World" "AE" "02-2007"
"John2" "Hello2" "World2" "AE2" "02-2007"
"John13" "Hello3" "World" "AE3" "02-2007"
"John14" "Hello4" "World4" "AE4" "02-2007"
"John15" "Hello5" "World5" "AE5" "02-2007"

What I need is to get the rows in file2 but not in file1. In addition
the comparision should not take the last filed as account (i.e.
"01-2007" and '02-2007" should not be considered). So in this case, I
wish to get:

"John13" "Hello3" "World" "AE3" "02-2007"
"John14" "Hello4" "World4" "AE4" "02-2007"
"John15" "Hello5" "World5" "AE5" "02-2007"
[...]

comm -13 file1 file2

if the files are sorted.

Non standard (bash, zsh, some kshs):

comm -13 <(sort file1) <(sort file2)

or (needs a system with /dev/fd/x):

sort file1 | { sort file2 | comm -13 /dev/fd/3 -; } 3<&0

See also:

sort file1 file2 | uniq -u

For lines that appear only once in the combined files.

--
Stéphane
.



Relevant Pages

  • Re: Text Script
    ... What is the template for the item you are searching for? ... I have file1 that comes from one ... I have File2 from another computer that is in no order either. ... > need to readline in file2 to find an account number. ...
    (microsoft.public.windows.server.scripting)
  • Re: Text Script
    ... I have file1 that comes from one ... I have File2 from another computer that is in no order either. ... need to readline in file2 to find an account number. ... > records to a third file on the same line, or to cause the original similar ...
    (microsoft.public.windows.server.scripting)
  • Re: Text Script
    ... I have file1 that comes from one ... >>> computer with dollar figures in it listed by account number in no ... I have File2 from another computer that is in no order either. ... >>> I know I need to use one file as my master to query the second file ...
    (microsoft.public.windows.server.scripting)
  • 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)