Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace a html comments using shell script

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?

like image 807
Harry Avatar asked Mar 05 '26 19:03

Harry


2 Answers

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

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

like image 51
Rohit Verma Avatar answered Mar 07 '26 08:03

Rohit Verma


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
like image 37
RomanPerekhrest Avatar answered Mar 07 '26 07:03

RomanPerekhrest