Try this...
Code:
while read value1
do
a=`echo $value1 | cut -d ' ' -f1`
b=`echo $value1 | cut -d ' ' -f2`
c=`echo $value1 | cut -d ' ' -f3`
x=`grep "$a" file2|sort -nr -k2,2|head -1|cut -d' ' -f1`
y=`grep "$a" file2|sort -nr -k2,2|head -1|cut -d' ' -f2`
z=`grep "$a" file2|sort -nr -k2,2|head -1|cut -d' ' -f3`
Diff=`expr $b - $y`
echo "$a $Diff $c $z" >>outfile
done <file1
Note:
file1 - your first file
file2 - your second file
outfile - the result file