2017-02-14 1 views
1

두 html 사이의 차이점을 얻으려고합니다. 그러나 문자열에 my-attribute이라는 속성이 있으면 diff를 계산할 때 my-attribute 및 해당 값을 무시하고 싶습니다.sed가 작동하지 않는 차이점

diff 유틸리티를 사용하여 파일간에 차이점을 얻고 있습니다.

아래 정규식은 diff 외부에서 작동합니다. 내가 같은 sed를 사용하는 경우

<html> 
    <body> 
     <div> 
      <span my-attribute="8885" >html1</span> 
     </div> 
    </body> 
</html> 

그러나 DIFF 내부

는, 그것은 나에게 이것은 오류를 제공

bash -c 'diff -y <(sed -E '[email protected](my-attribute)="[^"]*" @@g' html1.html) <(sed -E '[email protected](my-attribute)="[^"]*" @@g' html2.html)' 

구문 오류를주고 다음과 같이

sed -E '[email protected](my-attribute)="[^"]*" @@g' html1.html 

html1.html입니다 : 예기치 않은 토큰 근처에서 구문 오류가 발생했습니다. '('

올바른 명령을 얻으려면 도움이 필요하십니까?

편집 : 추가 html2.html

<html> 
    <body> 
     <div> 
      <span my-attribute="123" >html2</span> 
     </div> 
    </body> 
</html> 
+0

@Inian 유무는 = html2.html – ConfusionPrevails

답변

2

몇 글자 탈출해야합니다. 나를 위해

bash -c "diff -y <(sed -E '[email protected](my-attribute)=\"[^\"]*\" @@g' html1.html) <(sed -E '[email protected](my-attribute)=\"[^\"]*\" @@g' html2.html)" 

작품

+0

Karthick에게 감사드립니다. :) – ConfusionPrevails

0

어쩌면이 문제를 해결할 수 있습니다 :

$ cat html1.html | grep -v my-attribute > /tmp/tmp1 
$ cat html2.html | grep -v my-attribute > /tmp/tmp2 
$ diff /tmp/tmp1 /tmp/tmp2 
+0

내 요구 사항이 경우 속성 내-속성 = "123"내-속성을 내-속성과 그 부가가치를 무시하는 것입니다 추가 "8885". diff에는 html1과 html2 만 있어야합니다. – ConfusionPrevails

관련 문제