与 sed 的差异不起作用
Diff with sed not working
我正在尝试区分两个 html。但是如果字符串中有一个名为my-attribute的属性,我想在计算diff时忽略my-attribute及其值。
我正在使用 diff 实用程序来获取文件之间的差异。
下面的正则表达式在 diff 之外工作。
sed -E 's@( my-attribute)="[^"]*" @@g' html1.html
html1.html如下
<html>
<body>
<div>
<span my-attribute="8885" >html1</span>
</div>
</body>
</html>
但是在 diff 内部,如果我使用相同的 sed,它会给我一个语法错误
bash -c 'diff -y <(sed -E 's@( my-attribute)="[^"]*" @@g' html1.html ) <(sed -E 's@( my-attribute)="[^"]*" @@g' html2.html )'
这给出了错误:意外标记`('附近的语法错误
如果能帮助您正确执行命令,我们将不胜感激。
编辑:添加 html2.html
<html>
<body>
<div>
<span my-attribute="123" >html2</span>
</div>
</body>
</html>
也许这可以解决您的问题:
$ cat html1.html | grep -v my-attribute > /tmp/tmp1
$ cat html2.html | grep -v my-attribute > /tmp/tmp2
$ diff /tmp/tmp1 /tmp/tmp2
很少有字符需要转义。
bash -c "diff -y <(sed -E 's@( my-attribute)=\"[^\"]*\" @@g' html1.html ) <(sed -E 's@( my-attribute)=\"[^\"]*\" @@g' html2.html )"
适合我
我正在尝试区分两个 html。但是如果字符串中有一个名为my-attribute的属性,我想在计算diff时忽略my-attribute及其值。
我正在使用 diff 实用程序来获取文件之间的差异。
下面的正则表达式在 diff 之外工作。
sed -E 's@( my-attribute)="[^"]*" @@g' html1.html
html1.html如下
<html>
<body>
<div>
<span my-attribute="8885" >html1</span>
</div>
</body>
</html>
但是在 diff 内部,如果我使用相同的 sed,它会给我一个语法错误
bash -c 'diff -y <(sed -E 's@( my-attribute)="[^"]*" @@g' html1.html ) <(sed -E 's@( my-attribute)="[^"]*" @@g' html2.html )'
这给出了错误:意外标记`('附近的语法错误
如果能帮助您正确执行命令,我们将不胜感激。
编辑:添加 html2.html
<html>
<body>
<div>
<span my-attribute="123" >html2</span>
</div>
</body>
</html>
也许这可以解决您的问题:
$ cat html1.html | grep -v my-attribute > /tmp/tmp1
$ cat html2.html | grep -v my-attribute > /tmp/tmp2
$ diff /tmp/tmp1 /tmp/tmp2
很少有字符需要转义。
bash -c "diff -y <(sed -E 's@( my-attribute)=\"[^\"]*\" @@g' html1.html ) <(sed -E 's@( my-attribute)=\"[^\"]*\" @@g' html2.html )"
适合我