finding differences in 2 files

I have 2 simple files ...

This is file a.txt

A
B
D
E
F

This is file b.txt

F
A
B
C
D
E

Obviously Item C is missing - but how do I find this automatically.

Grep

Yes grep, like this

grep -v -x -f a.txt b.txt

Will yield

C

But take care - this is filename order dependant - as the switches in GREP are important.

switch meaning
-v Show non-matching lines
-x Match whole lines
-f Read Pattern from a file

But if you reverse the file order - you will produce nothing.

comm

I had never heard of this command utility....

But first we need sorted files.

sort -o a.txt a.txt
sort -o b.txt b.txt

Now we run the comm command.

comm a.txt b.txt

And we see the output

        A
        B
    C
        D
        E
        F

Which is nearly what we want ...

Using command switches we can now reduce this output.

comm -3 a.txt b.txt

Which yields

C