Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the Set - Subset of two files from the command line?

I have two files with sorted lines. One file (B) is a subset of the other file (A). I would like to find all lines in A that ARE NOT in B. Ideally, I would like to create a file (C) that contains these lines. Is this possible in Unix? I'm looking for a one line command to do this instead of writing a script. I looked at the join and diff commands, but I could not find a command option to do this. Thanks for the help.

like image 711
drbunsen Avatar asked May 18 '12 19:05

drbunsen


2 Answers

This will suppress common lines:

comm -3 a b
like image 114
johnshen64 Avatar answered Sep 28 '22 12:09

johnshen64


How about this:

grep -v -f B A > C
like image 40
johlo Avatar answered Sep 28 '22 11:09

johlo