in reply to How to extract duplicate lines from a text file?
You can use split to extract individual fields from a line. E.g. something like this:
... my $match_count = 1; my $prev_bead_id = ''; my $out = ''; while (my $line = <IFILE>) { my ($bead_id) = split ' ', $line; if ($bead_id eq $prev_bead_id) { $match_count++; } else { if ($match_count == $duplicate_count) { print $out; } $match_count = 1; $out = ''; } $prev_bead_id = $bead_id; $out .= $line; } # for when there is no further line after the last pair in the file: if ($match_count == $duplicate_count) { print $out; }
Update: fixed boundary case bug.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to extract duplicate lines from a text file?
by rnaeye (Friar) on Mar 01, 2011 at 13:30 UTC |