combine is a Perl script from moreutils, I recently found it might be useful after I stopped introducing these nice programs from moreutils.

You can use it as in the following command usages:


combine file1 and file2
combine file1 not file2
combine file1 or file2
combine file1 xor file2

Also supports - as standard input.

Here is an example case I could thing of, say an engaged couple is getting married and they need to sort out who should be in their guest lists. They decide each of them can invite ten guests, so here is their own lists:


% cat groomslist
Bryan Shreve
Dennis Peachey
Eugene Scherer
Jessen
Jonathan Rochelle
Katherine Levin
Kay Begin
Nicholas Jarrell
Russell Bennett
Verna Butcher

% cat brideslist
Bryan Shreve
Dennis Peachey
Elizabeth Bixler
Janet Denison
Jeff Suh
Jeremy Friedman
Jonathan Rochelle
Katherine Levin
Russell Bennett
Shelley Tisdale

The first thing, they want to know who are invited by both:


% combine groomslist AND brideslist
Bryan Shreve
Dennis Peachey
Jonathan Rochelle
Katherine Levin
Russell Bennett

And the bride wants to check if her lovely fiancĂ© and husband-to-be invites some girls which he shouldn’t put them in the list:


% combine groomslist NOT brideslist
Eugene Scherer
Jessen
Kay Begin
Nicholas Jarrell
Verna Butcher

After groom passes the test, they move on to check who are invited only by one party:


% combine groomslist XOR brideslist
Eugene Scherer
Jessen
Kay Begin
Nicholas Jarrell
Verna Butcher
Elizabeth Bixler
Janet Denison
Jeff Suh
Jeremy Friedman
Shelley Tisdale

Now, they can decide if they really want to invite those people. Also since they have five common guests, therefore they can each invite more quests to fill up empty seats. If they want to edit, using vimdiff might be a good idea to merge the files.

combine does not require files to be sorted. If you want to use normal tools, for example:


% diff groomslist brideslist
3,4c3,6
< Eugene Scherer
< Jessen
---
> Elizabeth Bixler
> Janet Denison
> Jeff Suh
> Jeremy Friedman
7,8d8
< Kay Begin
< Nicholas Jarrell
10c10
< Verna Butcher
---
> Shelley Tisdale

% diff groomslist brideslist | grep ^<
...

Those files have to be sorted to get correct result.