Comparing two text files and save the missing
I have two text files:
first text file:
Hello
Hi
Hola
Bonjour
Second text file:
Hi
Bonjour
How can I output the differences between them regardless the line number i.e. I want to save the output which is
Hello
Hola
Into a new text file
It's not clear what "the differences" means, but here is something that meets your given inputs and output:
$ cat >1
Hello
Hi
Hola
Bonjour
$ cat >2
Hi
Bonjour
$ diff --old-line-format='' <(sort 1) <(sort 2) >new
$ cat new
Hi
Bonjour
To output whole lines that exist in the first file but not in the second:
grep -vxFf second first
Alternatively, sort the files and then use comm
:
comm -23 <(sort first) <(sort second)