How to write the difference between two files into a file

comm -1 -3 a.txt b.txt > c.txt

The -1 excludes lines that are only in a.txt, and the -3 excludes lines that are in both. Thus only the lines exclusively in b.txt are output (see man comm or comm --help for details). The output is redirected to c.txt

If you want the difference between the two files, use diff rather than comm. e.g.

diff -u a.txt b.txt > c.txt

If you dont care for subset, you can use just

diff a.txt b.txt|grep ">"|cut -c 3- > foo.txt

.

$ cat a.txt
hello world
$ cat b.txt
hello world
something else
$ diff a.txt b.txt|grep ">"|cut -c 3- > foo.txt
$ cat foo.txt
something else

Tags:

Diff

Vimdiff