Pintu Kawar
Pintu Kawar

Reputation: 2156

Find different records between two files using Unix Commands

I have two files with shown records. How can I get the different records using Shell script/Unix Command. I don't want the common records from the both the files.

enter image description here

Thanks

Upvotes: 1

Views: 512

Answers (2)

maskacovnik
maskacovnik

Reputation: 3084

This should work:

grep -vf File1 File2
grep -vf File2 File1

Thanks for correction @jm666, this is nicer

Upvotes: 2

glenn jackman
glenn jackman

Reputation: 246774

It would have been nice to be able to copy and paste the input file text. Nevertheless:

comm -3 <(sort file1) <(sort file2) | sed 's/^\t//'

or

awk '
    {count[$0]++} 
    END {for (line in count) if (count[line] == 1) print line}
' file1 file2

Upvotes: 2

Related Questions