[英]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 . 我试图使用shell脚本取消注释html文件中的一行,但我无法为此编写一个sed命令。
I have a line 我有一条线
<!--<url="/">-->
I need to uncomment this line using shell script 我需要使用shell脚本取消注释这一行
<url="/"/>
sed -i -e "s|'<!--<url="/"/>-->'|<url="/">|g" myFile.html
Any idea how to replace this comment? 知道怎么替换这个评论吗?
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. 最好使用单引号,因为它会阻止对包括双引号在内的所有内容的解释。
You need to escape(add backslash) before /
character. 你需要在
/
character之前转义(添加反斜杠)。
Secondly, both crucial arguments should be separated with /
, but not with |
其次,两个关键参数都应该用
/
分隔,而不是用|
分隔 . 。
Use the following line: 使用以下行:
sed -i 's/<!--<url="\/">-->/<url="\/">/g' myFile.html
Use : sed -re 's/(<!--)|(-->)//g'
使用:
sed -re 's/(<!--)|(-->)//g'
eg: echo '<HTML><!--<url="/">--> <BODY>Test</BODY></HTML>' | sed -re 's/(<!--)|(-->)//g'
例如:
echo '<HTML><!--<url="/">--> <BODY>Test</BODY></HTML>' | sed -re 's/(<!--)|(-->)//g'
echo '<HTML><!--<url="/">--> <BODY>Test</BODY></HTML>' | sed -re 's/(<!--)|(-->)//g'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.