使用带有'diff'的正则表达式选项的问题

时间:2012-11-05 18:58:16

标签: regex shell diff

我一直试图做一个与此类似的事情...... Bash "diff" utility showing files as different when using a regex Ignore

已经好几个小时但没有运气。

我确信-I选项不起作用。以下是使用其他问题给出的示例的测试。

注意:我使用RHEL6附带的标准版“diff”,并且-I包含在手册页中,所以没有理由相信它不应该工作,但事实并非如此。任何帮助或指示都会受到赞赏

[toernerg@uschi12devwom27: ~] $ cat testfile1
// $Id: one
data

[toernerg@uschi12devwom27: ~] $ cat testfile2
// $Id: two
data

[toernerg@uschi12devwom27: ~] $ diff testfile1 testfile2
1c1
< // $Id: one
---
> // $Id: two

[toernerg@uschi12devwom27: ~] $ diff -I '.*\$\(Id\|Header\|Date\|DateTime\|Change\|File\|Revision\|Author\):.*\$.' testfile1 testfile2
1c1
< // $Id: one
---
> // $Id: two

[toernerg@uschi12devwom27: ~] $ diff --version
diff (GNU diffutils) 2.8.1

2 个答案:

答案 0 :(得分:0)

你的正则表达式需要两个地方的美元符号,但你的输入只有第一个。修复它,它的工作原理:

[user@host ~]$ cat testfile1
// $Id: one
data

[user@host ~]$ cat testfile2
// $Id: two
data

[user@host ~]$ diff -I '.*\$\(Id\|Header\|Date\|DateTime\|Change\|File\|Revision\|Author\):.*\$.' testfile1 testfile2
1c1
< // $Id: one
---
> // $Id: two
[user@host ~]$ diff -I '.*\$\(Id\|Header\|Date\|DateTime\|Change\|File\|Revision\|Author\):.*' testfile1 testfile2
[user@host ~]$ diff --version
diff (GNU diffutils) 2.8.1

(顺便说一下,实际上并不需要前导.*。)

答案 1 :(得分:0)

要在您的示例案例中工作,请尝试:

diff -I '\$\(Id\|Header\|Date\|DateTime\|Change\|File\|Revision\|Author\):'