views:

39

answers:

3

hi,

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..

+1  A: 

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

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

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.

John Pickup
could u please write me the code..
kapil
+2  A: 

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

pixelbeat