This is not nearly as elegant as ikegami's, but just another alternative...basically stores your input file into a hash with the first column as the key, incrementing the hash element each time it is encountered.
my ($col1, $col2);
my %index = ();
open INFILE, "<", "textfile.txt" or die "Can not open textfile.txt";
while ( <INFILE> ) {
chomp;
($col1, $col2) = split (/ /);
if (not exists $index{$col1}) {
$index{$col1} = 1;
}else{
$index{$col1}++;
}
close INFILE;
open OUTFILE, ">", "outfile.txt" or die "Can not open outfile.txt";
foreach my $value (sort keys %index) {
if ($index{$value} > 1) {
print OUTFILE "$value\n";
}
}
close OUTFILE;
Update: This only outputs the first column - need a bit more to plop out the entire line of input... |