views:

91

answers:

3

Are there any command line linux utilities that will give me the boolean difference between two text files?

Meaning:

File-A:

Apple  
Pear  
Orange   
Banana

File-B:

Pear  
Orange

Running

% program File-A File-B -o output

output:

Apple  
Banana 

Edit:

Awesome, thanks guys!

+1  A: 

The comm command is what you want here.

bmargulies
+3  A: 

Like this:

comm -2 -3 File-A File-B > output

This assumes that the files are sorted. Check man comm for more information.

Thomas
To sort them (bash syntax): `comm -3 <(sort -u File-A) <(sort -u File-B)`
Tobu
Hey, that's neat. I learn something new every day here :D
Thomas
A: 

Try this:

comm -3 file1.txt file2.txt | sed -r 's/^\t//'

This also catches items in file2 that are not in file 1.

Mark Byers