2

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?

1
  • 1
    Load file content into std::set<std::string>, then setA - setB? Commented Jul 8, 2013 at 0:59

2 Answers 2

2

diff A B returns

2d1 < fds 4d2 < asdf 
Sign up to request clarification or add additional context in comments.

1 Comment

I personally prefer the output of diff -u, but yes, diff is a very useful program that all *nix users should be aware of.
0

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.