in reply to removing non-duplicates
Here's a command-line variant of other solutions offered:
If you don't care to preserve the original order of lines then:% perl -ne 'push @a, $_; $h{$_}++; END { print for grep $h{$_}==1, @a +}' foo.txt
% perl -ne '$h{$_}++; END { print for grep $h{$_}==1, keys %h }' foo.t +xt
the lowliest monk
|
|---|