使用sed命令替换favicon的url不起作用

时间:2013-12-06 09:54:22

标签: sed favicon

我想使用c替换html文件中存在的URL作为快捷方式图标。我使用sed替换url,但命令发出错误,因为即使图标出现在指定位置也无法读取图标。

如果我手动更换网址,它可以正常工作。

我的命令是:

sed -i '/<link id=/c\\<link id='test' rel='shortcut icon' href='path_of_icon' type='image/x-icon'/>' path_of_html_file

2 个答案:

答案 0 :(得分:0)

sed -i "s|<link id=|<link id='test' rel='shortcut icon' href='path_of_icon' type='image/x-icon'|" path_of_html_file
  • 您只使用'所以shell混合内容和解释
  • 您忘记了第一个s替换订单
  • 您使用/作为模式的副本,但/也在您的模式中

答案 1 :(得分:0)

如果你想使用sed'change'命令来替换包含“link id = ...”的整行,那么为什么不将它放入脚本文件并通过-f来源?这将有助于引用问题(我相信你的错误是由于引用,如前所述):

s.sed:

/<link id=/c\
<link id='test' rel='shortcut icon' href='path_of_icon' type='image/x-icon'/>

然后

sed -i -f s.sed path_of_html_file

完全有可能在命令行上执行此操作,但处理其他引号内的引号的所有内容在cmdline上都会变得非常难看。

相关问题