sflee
sflee

Reputation: 1719

Compare two files, find the difference?

I have two files with the following structure.

File A:

asd
fds
sdf
asdf

File B:

asd
sdf

I want to find the difference between these two files.

This time the result should be fds, asdf.

How can I do it with c++ or linux?

Upvotes: 2

Views: 3448

Answers (2)

jww
jww

Reputation: 102444

This answer was posted by @sflee in his question. It was moved into this answer block.

Solution:

Here is the way I used finally, just in case that I forget this in the future. I got A.txt and B.txt:

sort A.txt | uniq > A2.txt
sort B.txt | uniq > B2.txt
diff A2.txt B2.txt | grep '<' > data_B2_is_missing.txt

Upvotes: 0

Aman Deep Gautam
Aman Deep Gautam

Reputation: 8787

diff A B returns

2d1
< fds
4d2
< asdf

Upvotes: 2

Related Questions