sumit vedi
sumit vedi

Reputation: 777

Difference between two files

I have two files. I want to compare the files but the order of the rows is not same in both files. Can you please provide the simplest method to compare the both files.

Example:

file1

My name is sumit.
My surname is vedi.
I like shell scripting.

file2

My surname is vedi.
My name is sumit.
I like shell scripting.

The difference between the files should be zero; however, the order of the rows is not same. Note: the files are huge.

Upvotes: 0

Views: 637

Answers (1)

Vijay
Vijay

Reputation: 67291

Probably the command below would do the thing.

diff <(sort file1) <(sort file2)

If the files are huge and you do not need a sort command, then may be you could use awk:

awk 'FNR==NR{a[$0];next}!($0 in a)' file1 file2

The above command will only give the lines that are present in file2 but not in file1.

Upvotes: 1

Related Questions