2016-07-20 10 views
-3

基本的には、HTMLファイルを変更するためにSED(Linux版)を使用します。そのコードを実行すると、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は空白や改行が明らかに何であるかを知ることができないので、 "unknown command"というエラーが出ます。 –

+0

奇妙なことに、 "unterminated 's'コマンド"というエラーが出ます。これは、 's'コマンドの引数にリテラル改行が含まれてはならないという事実によるものです。 –

答えて

0

sedの変更コマンドを使用します。

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アドレス範囲の終わりに、標準出力にテキストが書き込まれます

関連する問題