2016-07-20 193 views
-3

基本上我想要做的就是使用SED(linux版本)在HTML文件中进行更改。当我执行该代码时,我得到一个“未知命令”错误,因为sed无法明确显示空白或换行符。SED空格/换行符匹配 - Linux

sed 's|<a href="es/map-button.html"> 
      <div class="map-button">|<div id="confirmation" onclick="confirmation()" class="map-button"> 
      <script type="text/javascript"> 
<!-- 
       function confirmation() { 
       var answer = confirm("Access map? (uses internet)") 
        if (answer){ 
        window.location = "google.maps.com";; 
        } 
        else{ 
        //alert("Returning to current content") 
        } 
       } 
//--> 
      </script>|g' *.html 

我的分隔符是“|”你在这里看到的。

+0

有什么问题?你面临的问题是什么? – Fazlin

+0

抱歉应该指定更多。基本上,当我执行该代码时,我得到一个“未知命令”错误,因为sed无法分辨明显是什么空白或换行符。 –

+0

奇怪的是,我得到错误“未终止的'命令”,这是由于's'命令的参数不能包含字面换行符。 –

回答

0

使用sed的change命令。

sed '/<a href="es\/map-button\.html">/{ 
    N 
    /<div class="map-button">/c\ 
<div id="confirmation" onclick="confirmation()" class="map-button">\ 
<script type="text/javascript">\ 
<!--\ 
function confirmation() {\ 
    var answer = confirm("Access map? (uses internet)")\ 
    if (answer){\ 
     window.location = "google.maps.com";;\ 
    }\ 
    else{\ 
     //alert("Returning to current content")\ 
    }\ 
`}\ 
//-->\ 
</script> 
}' *.html 

/address/c\ 
text 

删除模式空间。在0或1地址或2地址范围的末尾,文本被写入标准输出