如何忽略以diff开头的行? [英] How to ignore lines starting with a string with diff?
问题描述
如何区分两个文件并忽略以序列开头的行。
How can I diff two files and ignore lines starting with a sequence.
例如
File1:
abc
def
time:123
File2:
igh
def
time:345
使用unix diff将报告
With unix diff it will report
<time:123
>time:345
我想忽略这个差异。有想法吗?
I want to ignore this diff. Any ideas?
推荐答案
怎么样: diff -I'^ time。*'file1 file2
?
Please not it doesn't always work as expected as per diffutils
manual:
但是,
-I
仅忽略如果大块中每条更改的行(每次插入和每次删除)都与正则表达式匹配,则包含正则表达式的行的插入或删除。
However,
-I
only ignores the insertion or deletion of lines that contain the regular expression if every changed line in the hunk (every insertion and every deletion) matches the regular expression.
换句话说,对于每个不可忽略的行更改, diff
会在其附近显示完整的更改集,包括可忽略的更改。您可以使用多个 -I
选项为忽略的行指定多个正则表达式。 diff
尝试将每个行与每个正则表达式匹配,从给定的最后一个开始。
In other words, for each non-ignorable change, diff
prints the complete set of changes in its vicinity, including the ignorable ones. You can specify more than one regular expression for lines to ignore by using more than one -I
option. diff
tries to match each line against each regular expression, starting with the last one given.
这篇关于如何忽略以diff开头的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!