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!

noli
  • 15,927
  • 8
  • 46
  • 62

3 Answers3

3

Like this:

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

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

Thomas
  • 174,939
  • 50
  • 355
  • 478
1

The comm command is what you want here.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
0

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
  • 811,555
  • 193
  • 1,581
  • 1,452