[RndTbl] bash script for printing lines that don't match?

Adam Thompson athompso at athompso.net
Tue Sep 18 12:35:44 CDT 2012


( grep -F fileb -v filea ; grep -F filea -v fileb ) | sort | uniq

You can simplify that quite a bit if you only need a one-way comparison.
This will only work with text files, although it will work with NCS/locales if you have LANG et al. set correctly.

-Adam

John Lange <john at johnlange.ca> wrote:

>I think I've asked this in the past but try as I might I can't
>remember what the answer was or figure out how I solved it before.
>
>I have 2 files that are nearly identical and I need to know which
>lines in the two files do _not_ match.
>
>I can think of some relatively complex loops with grep etc. which
>would probably work (for every line in file A, grep in file B etc.)
>solve the problem but I'm hoping for something more elegant.
>
>I thought at first that perhaps "join" would do it but even though it
>will provide left and right joins, there is no way to prevent it from
>outputting the matching lines.
>
>Any ideas?
>
>John
>_______________________________________________
>Roundtable mailing list
>Roundtable at muug.mb.ca
>http://www.muug.mb.ca/mailman/listinfo/roundtable



More information about the Roundtable mailing list