0

I am having the below text in my-config file

<!--<URL>www.abc.com</URL>-->
         www.xyz.com

I want to uncomment the commented line and comment the uncommented line. I tried using the sed command

 sed -i '/<!--<URL>www.abc.com</URL>-->/s/^#//g' filename

but getting error as

sed: -e expression #1, char 24: unknown command:/'`

please help in resolving this or correct if anything wrong in my sed command. Thanks in advance.

Mallik
  • 679
  • 2
  • 14
  • 18
  • What commented line? [edit] your question to include concise, testable sample input and the expected output given that input. – Ed Morton Apr 13 '17 at 21:03

1 Answers1

1

Since you're using the '/' as the sed delimiter, you must escape '\' the '/' in the tag.

e.g.

 sed -i '/<!--<URL>www.abc.com<\/URL>-->/s/^#//g' filename

You can also switch your delimiter in sed for better readability more.

James
  • 113
  • 1
  • 7
  • Same situation. When you have characters that match your delimiter you must escape them or choose an alternate delimiter. – James Apr 13 '17 at 13:47
  • It takes more than escaping delimiters. See [is-it-possible-to-escape-regex-metacharacters-reliably-with-sed](http://stackoverflow.com/questions/29613304/is-it-possible-to-escape-regex-metacharacters-reliably-with-sed). In the OPs case all those `.`s would need to be escaped too. The correct solution when you want to search for a string instead of a regexp is to just use awk since it understands strings. – Ed Morton Apr 13 '17 at 21:07