http://www.perlmonks.org?node_id=1093138


in reply to Sorting By Column

If file identity in column 1 were omitted, you could use the unix comm utility to eliminate duplicates.

See if this works to your satisfaction (give input files as arguments):

#! /usr/bin/perl my %X; for (<>) { my ($i,$k,$n) = split(" ",$_,3); $X{$k.$n}{$k.$i} = $_; } for (sort {$a->[0] cmp $b->[0]} map [%$_], values %X) { print $_->[1] if @$_ == 2; }