Click to See Complete Forum and Search --> : How do I use diff for getting what's missing in file 2?


xs411
06-09-2003, 01:09 PM
I have two files that have a list of items. File 1 contians a list of items that I have already processed and file 2 contains some that I have processed and some that I haven't. I want to find the unprocessed items in file 2 and then output the items to a file. How do I use diff to do this? I looked through the manual but it seems like I'm always going to get extra info like line numbers and the stuff that's in file 1 that's not in file 2. I don't need to know this, only what's in file 2 but not in file 1.

Any help is appreciated.

Scott

Strogian
06-09-2003, 01:24 PM
I don't think there's an option for diff to do that, based on what I saw in the manpage. But this will do it:

diff file1 file2 | sed -n -e '/^> /s/^> //p'

(prints out only the output of diff that matches this pattern
> blahblah
and strips off the leading '> ')

hlrguy
06-09-2003, 01:32 PM
diff <file1> <file2> |difffile
vi/gedit/kedit/diffile

The lines showing <---are in file1, the
other direction is file2.

You made me realize that Redhat 8.0 doesn't have kdiff. That is a GUI program which makes diff a joy. I just installed gtkdiff, here.

http://www.hklpg.org/RPM/sourceforge/gtkdiff/gtkdiff-1.0.0-2.i386.html

hlrguy

dchidelf
06-09-2003, 01:54 PM
comm works good for this sort of thing:

comm -23 file1 file2 -- show lines only in file1
comm -13 file1 file2 -- show lines only in file2
comm -12 file1 file2 -- show lines in both files

xs411
06-09-2003, 02:13 PM
Thanks for your prompt reply. You were all very helpful. That comm thing sounds like it'll do the trick. I'll post again if I can't get it to work. Once again thank you very much!

scott