# Passing Parameter in SED command

**URL:** <https://community.unix.com/t/passing-parameter-in-sed-command/200023>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [June 6, 2008, 6:18pm UTC](https://community.unix.com/t/passing-parameter-in-sed-command/200023 "2008-06-06T18:18:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsrookie](https://community.unix.com/letter_avatar/dsrookie/32/5_5575768a8748004e209b776fc1b2916d.png) [@dsrookie](https://community.unix.com/u/dsrookie)\
**Post date:** [June 6, 2008, 6:18pm UTC](https://community.unix.com/t/passing-parameter-in-sed-command/200023/1 "2008-06-06T18:18:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robotronic](https://community.unix.com/user_avatar/community.unix.com/robotronic/32/57_2.png) [@robotronic](https://community.unix.com/u/robotronic)\
**Post date:** [June 7, 2008, 5:46am UTC](https://community.unix.com/t/passing-parameter-in-sed-command/200023/2 "2008-06-07T05:46:33Z")

</div>

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 "!"):

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

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

```

---

<div class="post-metadata">

**Author:** ![dsrookie](https://community.unix.com/letter_avatar/dsrookie/32/5_5575768a8748004e209b776fc1b2916d.png) [@dsrookie](https://community.unix.com/u/dsrookie)\
**Post date:** [June 9, 2008, 1:25am UTC](https://community.unix.com/t/passing-parameter-in-sed-command/200023/3 "2008-06-09T01:25:52Z")

</div>

Thanks a lot robotronic...it works perfectly fine
