2

diff -I option does't work for me when there is an mismatch before skipped lines.

File1:

a1 * b 

File2:

a2 * c 

$ diff -I '*' File1 File2

< a1 < * b > a2 > * c 

But if in both files the first line is "a1", the output will be clear. Is there any suggestions how to skip lines when there is an mismatch before that lines? Thanks.

3
  • Please clarify: Do you want to skip those lines always? Commented Jul 29, 2013 at 9:04
  • What I understand is that diff -I '*' File1 File2 should skip * b lines, but it does not. Hence the question is "how to do it", as when the first line is equal it does skip it. Commented Jul 29, 2013 at 9:32
  • Yes, the question is how to get diff only for a1 and a2 from diff -I '*' File1 File2 Commented Jul 29, 2013 at 9:36

1 Answer 1

1

The behaviour that you're observing can be well explained by this comment.

To elaborate, if the input files were to read:

$ cat 1 a1 * b $ cat 2 a2 * c 

then diff with -I would give you the expected output:

$ diff -I$'*' 1 2 1c1 < a1 --- > a2 

In your case, you might use alternatives such as:

$ diff <(sed '/^\*/d' 1) <(sed '/^\*/d' 2) 1c1 < a1 --- > a2 
Sign up to request clarification or add additional context in comments.

2 Comments

With your provided example when there is an empty line between mismatch and skipped lines the result is what I expected, but without empty line it didn't work. The second suggestion works as expected but I wander I will have a bad performance with it. The think is that the diff is providing such option for skipping, can we have it always work? Or there is a bug in diff.
You didn't read the first line that essentially said that your observing is the expected behaviour. The suggested workaround shouldn't really have a performance impact unless the input files were to be massive in size.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.