in reply to find duplicates and write to file
Update: This only outputs the first column - need a bit more to plop out the entire line of input...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;
|
|---|