sed-command

hello all

Iam using this command to substitute the existing line with a # here

sed -i '/url-map = etc/url.c/ s/url-map = etc/url.c/#url-map = etc/url.c/' con.txt

while using this command iam getting errors like

sed: -e expression : Extra characters after command

Any suggestions on how to proceed...thanks a lot for your help folks..

Escape the slashes in the patterns and strings so that sed can distinguish between them and sed's own syntax.

Or use a different delimiter, say ?:

sed -i '\?url-map = etc/url.c?s?^?#?' con.txt

Also, note that you don't need to replace the entire line with a new value, you can just replace the beginning of the line with a #.

That will not work for the address selector; that has to use slashes.

I only discovered this feature on HP-UX today (from man sed):

           +  In a context address, the construction \?regular expression?,
              where ? is any character, is identical to /regular
              expression/.  Note that in the context address \xabc\xdefx,
              the second x stands for itself, so that the regular expression
              is abcxdef.

It seems to work with GNU sed and on AIX too... I'd be curious to see whether it is common on the OSs you have access to, because it's a feature I've overlooked for some years?

Try this:

sed -i '/url-map = etc\/url.c/ s%url-map = etc/url.c%#url-map = etc/url.c%' con.txt

It is part of the POSIX standard. I had forgotten that.

AWESOME!! thanks alot guys for helping me out (cfajohnson,Annihilannic,danmero) really appreciate ur help..