0

I have to compare two files which are like

    A                      B
   ---                    ---    
  110-01                 110-01
  120-02                 110-02
    ...                  120-02
                          ....

and have to print what are the extra elements present in the B file..

3 Answers 3

2

You want the set difference.

For sorted files:

join -t'\0' -v2 file1 file2

For unsorted files:

sort file1 file1 file2 | uniq -u

For more set ops see http://www.pixelbeat.org/cmdline.html#sets

Sign up to request clarification or add additional context in comments.

Comments

1

You need diff: http://ss64.com/bash/diff.html

1 Comment

Though it is pretty useless if your files consist only of one single line containing values seperated by space or comma
0

diff is the obvious choice but that of course compares at the line level and is appears the tokens present in your file are separated by spaces. You could use sed to change spaces to lines. Next sort both files and finally diff.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.