2017-02-14 30 views
1

我想獲得兩個htmls之間的差異。但是如果字符串中有一個名爲my-attribute的屬性,我想在計算diff時忽略my-attribute和它的值。與sed不能正常工作的差異

我使用diff實用程序來獲取文件之間的差異。

下面的正則表達式在diff之外工作。

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

html1.html如下

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

但內部差異,如果我用同樣的SED,這是給我一個語法錯誤

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

這給了錯誤: ('

將不勝感激任何幫助,以獲得正確的命令。

編輯:添加html2.html

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

@Inian添加html2.html – 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」。差異應該只有html1&html2 – ConfusionPrevails