views:

73

answers:

1

Hello, I have two lists of names, A and B. I need to produce three lists:

1) names only on A

2) names only on B

3) names on both A and B

I also have a list with all the names on A and B, C.

Can anyone think of Unix tools or quick scripts to do this?

+1  A: 

use the command comm.

This does exactly what you want.

Alex Brown
Thanks! Using the -1, -2, -3 flags I was able to supress the output and get exactly what I wanted.comm [OPTION]... LEFT_FILE RIGHT_FILE DESCRIPTIONCompare sorted files LEFT_FILE and RIGHT_FILE line by line.-1 suppress lines unique to left file -2 suppress lines unique to right file -3 suppress lines that appear in both files
It's worth noting that you need to SORT your input files before feeding them into comm. This can be done like this:comm <(sort -u left_file) <(sort -u right_file)
Alex Brown