I want to seperate all the duplicate records to a duplicate file and write out all the unique records to a unique file.
My input file is about 10MB and the records are sorted numerically. Here is the sample records:
00000
11111
11111
11115
22222
33333
33333
33333
44444
55555
and so on.
The dups file should look like:
11111
11111
33333
33333
33333
The unique file should look like:
00000
11115
22222
44444
55555
Here is my code:
open(IN, $ifile);
open(UNQ, $ufile);
open(DUP, $dupfile);
my %seen;
while (<IN>) {
if ( exists( $seen{$_} )) {
print DUP "$_\n";
}
else {
$seen{$_}++;
print UNQ "$_\n";
}
}
close(IN);
close(UNQ);
close(DUP);
My code will not be able to pull ALL the duplicates to the dup file. Instead, it will keep the first duplicate record in unique file and write the rest of the duplicate records to the dup file.
Any suggestion?
edited: Fri Aug 8 13:37:06 2003
by jeffa - code tags, removed br tags, added readmore
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.