Need to pass value in sed command

Hi,

I have a file a.xml containing the below

<customerId>000</customerId>

and a variable CUSTOMER_ID which is set to '333'

Now I want to replace <customerId>000</customerId> with <customerId>333</customerId> by the below sed command and save the output in a file b.xml:

sed 's/<customerId>\([0-9]*\)/<customerId> ${CUSTOMER_ID}/' a.xml > b.xml

But when I open b.xml after running the sed command, I see the below result :

<customerId> ${CUSTOMER_ID}</customerId>

Please help.

use double quotes

 
 
$ CUSTOMER_ID=300
$ echo "<customerId>000</customerId>" | sed "s/<customerId>[0-9]*/<customerId>${CUSTOMER_ID}/"
<customerId>300</customerId>

sed 's/<customerId>\([0-9]*\)/<customerId>'"$CUSTOMER_ID"'/' a.xml > b.xml

Many thanks. The solutions worked.