Re: diff command ignoring question



On 2012-01-24 15:21, Bit Twister wrote:
May not work on all distributions.

$ diff -I this -I that a a1
[or]
$ diff -I '\(this\)\|\(that\)' a a1
3c2,3
< good
---
> this
> bad


$ cat a
this
that
good

$ cat a1
that
this
bad

Works fine. Check again what exactly -I does and remember that
diff works with "hunks", which means it doesn't necessarily compare
line 21 from one file to line 21 from the other. In your example
all three lines differ and diff arbitrarily chooses line "that"
to be the common line of a hunk, and this happens to be line 2
in file "a" but line 1 in "a1".

So here diff processes like this: line "this" needs to be removed
from "a" to match "a1" but since it matches the pattern specified
by -I, ignore it. Line "that" stays untouched, ignore it.
Line "good" needs to be removed from "a" to match "a1", show it.
Lines "this" and "bad" need to be inserted. Although line "this"
should be ignored because it matches the pattern specified
by -I, the very next line, "bad", doesn't match and thus
cannot be ignored, so need to show them both because "for each
nonignorable change, `diff' prints the complete set of changes
in its vicinity, including the ignorable ones." (see 'info diff')

Change "bad" to "good" in "a1" and see that the changes in the first
two lines will be ignored.

--
mrg
.



Relevant Pages