Modify a file

Hi all

Can anyone suggest me a good solution ? My requirement is as follows
I have a plain text file similar to this...

sending data to 0003345234
here is the output...
,..........
...........
.......
sending data to 00033452ab
here is the output...
,..........
...........
.
.......
sending data to 00033abfbb
here is the output...
,..........
...........
abcabc----
.......

----------------------------------------

Now I want to modify this file as follows

sending data to 0003345234 Mumbai

here is the output...
,..........
...........
.
.......
sending data to 00033452ab Culcutta
here is the output...
,..........
...........
.
.......
sending data to 00033abfbb Pune
here is the output...
,..........
...........
.
.......

----------------------------------------

I have a comparison file also like
00033abfbb Pune
00033452ab Culcutta
003345234 Mumbai

Now the problem is, in the orginal file some time there would be some white spaces at the end of the line.

Cheers
Hari

Search this site for NR==FNR

That coudnt help me..
Let me tell you abt the script I am using now.....

for i in `grep Sending $h | awk '{print $8}'`
do
SYSID=`grep $i compare.file | awk '{print $3}' | head -1`
LOCATION=`grep $i compare.file | awk '{print $2}' | head -1`
sed 's/'${SYSID}$'/'${SYSID}' '${LOCATION}'/g'  $h  > tmp
cat tmp > $h
done

This works but, where ever the $h file has spaces (one space or some times two) after the SYSID, it doesn't
Also note that SYSID is a MAC address which has alpha numeric characters and the SYSID may repeat in between the lines not at last, where I don't want to add the LOCATION.

awk 'NR==FNR { loc[$1] = $2; next }
/sending/ { print $0, loc[$3]; next }1' compare.file "$h"

Its not working! Pls check again

Did you ask yourself why?