in reply to Finding duplicate keys

> but I suspect there's a more elegant way to do this (perhaps even as a one-liner).

Well, not that there's anything wrong with everyone else's responses, but I just thought I'd take a crack at it as a one-liner:

perl -lne 'exists $h{$_} ? print "$_ in $h{$_} and $ARGV" : ($h{$_} = +$ARGV)' file1 file2

That's only semi-tested, but it seems to work for me. And you could send it as many files as you liked (although it wouldn't be smart enough to say something like "key in file1 and file2 and file3"; it would instead say "key in file1 and file2" and then later "key in file1 and file3").

This assumes the entire line is the key, which probably isn't the case. Here's a slightly modified version which might, say, catch duplicate uids in two Unix password files:

perl -F: -lane 'exists $h{$F[2]} ? print "$F[2] in $h{$F[2]} and $ARGV +" : ($h{$F[2]} = $ARGV)' passwd1 passwd2

I'm sure the wiser monks will jump in if there's some "gotcha" I missed ...