Passing Parameter in SED command

Hi,

I am trying to replace a URL by another URL in the SED command e.g.

cat dir/filename1 | sed -e 's/"http:\/\/[^ ]*dtd"/"http:\/\/abc.def.com\/xyz.dtd"/' > dir/newfile.xml

But I need to pass a parameter to the SED command which should have the new url string i.e. http:\/\/abc.def.com\/xyz.dtd

$NEW_URL=http:\/\/abc.def.com\/xyz.dtd

I tried

cat dir/filename1 | sed -e 's/"http:\/\/[^ ]*dtd"/"$NEW_URL"/' > dir/newfile.xml

but instead of passing the new url, the old url was replaced by string '$NEW_URL' i.e. the parameter did not get replaced by its value.

Please help me in finding how can this be achieved.

Thanks
dsrookie

You need to use double quotes. By the way, you can also avoid cat command and avoid escaping all slashes, providing a sed "delimiter" other than "/" (in my example I've used "!"):

NEW_URL="http://abc.def.com/xyz.dtd"

sed "s!http://[^ ]*dtd!${NEW_URL}!" dir/filename1 > dir/newfile.xml

Thanks a lot robotronic...it works perfectly fine