help with SED/AWK

Hi:
I have a file(ex: file1) containing strings like \$\$VAL1\$\$ value1 in each line.

Now I want to read all these strings from this file1 and replace the value of $$VAL1$$ with the "value1" in another file (ex: file2).

I tried something like:
------------------------------------------------------
#!/bin/ksh

VALUE1=`awk '/VAL1/ {print $2}' file1`
cat ./file2 | sed "s/\$\$VAL1\$\$/"$VALUE1"/" > ./temp
mv temp file2
------------------------------------------------------

but the "sed" part is not working as expected. plz help.

it is working for normal case.

but in my case the string will be: $$VAL1$$ /home/xyzzz/

so while substituiting with sed, sed is confused as it has "/" character in the string.

I am getting the following error:
sed: command garbled: s/$$VAL1$$//home/xyzzz/

any help is appreciated.

awk '
ARGV[1]==FILENAME && /VAL1/ { value = $2 }
ARGV[2]==FILENAME { sub( /\$\$VAL1\$\$/, value ); print }
' file1 file2

Thanks for the reply.

I am getting the following error.

awk: syntax error near line 3
awk: illegal statement near line 3

any clues..?

as always..... if under Sun/Solaris, use 'nawk'' istead of 'awk'

Even better perhaps, /usr/xpg4/bin/awk

Thank You ALL for your help.