如何忽略diff命令有哪些区别? [英] How to ignore some differences in diff command?
问题描述
差异
具有忽略插入删除匹配给定的行带来的改变的一个选项 -I正则表达式
,正则表达式。我需要这样一个模拟的情况下,当变化是两条线(而不是插入或删除线)。
diff
has an option -I regexp
, which ignores changes that just insert or delete lines that match the given regexp. I need an analogue of this for the case, when changes are between two lines (rather then insert or delete lines).
例如,我想忽略像abXd
和abYd
,对于给定的所有区别 X
和是
。
For instance, I want to ignore all differences like between "abXd"
and "abYd"
, for given X
and Y
.
这似乎差异
还没有这样的一种能力。是否有任何合适的替代差异
?
It seems diff
has not such kind of ability. Is there any suitable alternative for diff
?
推荐答案
您可以过滤通过 SED
这两个文件,以消除你不关心的线条。一般的模式是 / regex1的/,/ regex2 / D
删除匹配两段正则表达式行之间的任何东西。例如:
You could filter the two files through sed
to eliminate the lines you don't care about. The general pattern is /regex1/,/regex2/ d
to delete anything between lines matching two regexes. For example:
diff <(sed '/abXd/,/abYd/d' file1) <(sed '/abXd/,/abYd/d' file2)
这篇关于如何忽略diff命令有哪些区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!