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

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


This will suppress common lines:

comm -3 a b


How about this:

grep -v -f B A > C


You can do this with diff as well. Diff (unlike @johlo's grep answer) cares about order, works on non-sorted files (unlike @johnshen64's comm answer) :

$ cat aabcde$ cat babfde$ diff -dbU0 a b--- a   2012-05-18 16:02:30.603386016 -0400+++ b   2012-05-18 16:02:45.547817122 -0400@@ -3 +3 @@-c+f

So you can use a pipeline to get just the omitted lines—considering order:

$ diff -dbU0 a b | tail -n +4 | grep ^- | cut -c2-c