This works for the example given, and is quite simple:
grep -v -F "`grep -o .*= file1`" file2
I tried it on an artificially-created 30000 line file, and it was fast.
It just uses grep -o
to create a list of matches which is then fed into grep -F
as fixed strings. Then -v
is used to say 'show lines that don't match'
Some caveats:
- this is case sensitive, so
A=10
is different from a=10
.
- there's an assumption that there is exactly one '=' sign on any line that's significant in file1, and that everything to the left of it (including spaces) is part of the check.
- Probably a bug if file1 contains A=10 and file2 contains AAA=10, A=10 will be found in file2, and therefore that line won't be reported. I'll try to rewrite the one-liner to fix this bug
Another option, which is simpler and actually nicer
join -t= -v 2 <(sort file1) <(sort file2)
This one requires file1 and file2 to be sorted first, but doesn't show the bug that the grep
version above shows. It's also probably faster (I haven't really checked). The other caveats above still apply.