3

I am trying to uncomment a line in html file using shell script but I am not able to write a sed command for this .

I have a line

<!--<url="/">-->

I need to uncomment this line using shell script

<url="/"/>
sed -i -e "s|'<!--<url="/"/>-->'|<url="/">|g" myFile.html

Any idea how to replace this comment?

1
  • Use a different separator for sed for example I often use % instead of ". That way you have no problems escaping quotes Commented Jul 1, 2016 at 14:01

3 Answers 3

3

Use : sed -re 's/(<!--)|(-->)//g'

e.g: echo '<HTML><!--<url="/">--> <BODY>Test</BODY></HTML>' | sed -re 's/(<!--)|(-->)//g'

Sign up to request clarification or add additional context in comments.

Comments

1

You need to escape(add backslash) before / character.
Secondly, both crucial arguments should be separated with /, but not with |.
Use the following line:

sed -i 's/<!--<url="\/">-->/<url="\/">/g' myFile.html

Comments

0

Like this?

sed -i 's|<!--<url="/">-->|<url="/">|g' myFile.html

It's better to use single quotes because it prevents interpretation of everything including double quotes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.