Diff and ignore lines missing in one file

Posted by Millianz on Super User See other posts from Super User or by Millianz
Published on 2012-04-06T21:58:38Z Indexed on 2012/04/06 23:34 UTC
Read the original article Hit count: 207

Filed under:
|
|
|

I want to diff two files and ignore lines that are present in one file but missing in the other.

For example

File1:

foo
bar
baz
bat

File2:

foo
ball
bat

I'm currently running the following diff command

diff File1 File2 --changed-group-format='%>' --unchanged-group-format=''

Which in this case would produce

bar
baz

as the output, i.e. only missing or conflicting lines. I would like to only print conflicting lines, i.e. ignore cases where one line is missing from File2 and is present in File1 (not the other way around). Is there any way to do something like this using diff or do I have to resort to other tools? If so, what would you recommend?

© Super User or respective owner

Related posts about bash

Related posts about shell