2016-07-20 3 views
-3

기본적으로 내가하고 싶은 것은 SED (리눅스 버전)를 사용하여 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

이상하게도,''unterminated 's'명령 "오류가 발생합니다. 이는's' 명령에 대한 인수가 리터럴 새줄을 포함해서는 안되기 때문입니다. –

답변

0

sed의 변경 명령 ​​사용.


/address/c\ 
text 

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 

패턴 영역을 삭제합니다. 0 또는 1 주소 또는 2- 주소 범위의 끝에서 텍스트는 표준 출력에 기록됩니다.