【发布时间】:2012-05-17 18:32:17
【问题描述】:
我有一个需要编辑的 300 多个文件的列表,所以我认为 sed 命令与 find 和 exec 结合使用可以帮助我。
在做错事(比如覆盖我不会修改的文件或类似的事情)之前,我决定使用 sed 并将他的结果输出到 bash 而不是本地替换。
我正在搜索的字符串是:<tr><td class="button" style=" background:#040404; color:#eee9dc; font-size: 23px; padding:5px 0; text-align:center;"><a href="../Z2/C24357-0/hhcm-LASTMINUTES.html" style=" text-decoration:none; cursor:pointer; color:#eee9dc">Offerte & LastMinute</a></td></tr>
我只想用 <a href="../../../special_offers.php?lang=it" 替换 <a href="../Z2/C24357-0/hhcm-LASTMINUTES.html 的那部分
由于我是 regex 的菜鸟,我将看看 web page 以一种体面的方式将我带入正则表达式参数。
现在,我尝试了类似的方法(在单个文件上,只是为了以“安全”的方式查看输出)
sed s/\<a.*LAST.*html\"
/\<a href="\.\.\/\.\.\/\.\.\/special_offers\.php\?lang=en"/
C25030-9_3/hhcm-Solo_per_due.html
我得到了那个错误:sed: -e expression #1, char 20: unterminated s' command
就像sed 表达式不正确,但我不知道错误是在replacement 部分还是其他地方。
从现在开始感谢您的时间和精力。
S.
编辑
感谢回答,我通过这样做解决了这个问题
sed 's/<a.*LAST.*html\"/\<a href="..\/..\/..\/special_offers.php?lang=en"/' C25030-9_3/hhcm-Solo_per_due.html
【问题讨论】: