2017-02-14 42 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