With only about 3 million unique id's, a memory resident hash table is completely feasible. An easy approach is to read all of the input data twice and output a subset of the input data once.

my %hash; open file1... while (<$file1>) { ... do something to get the id $hash{$id}++; } close file1 open file 2 while (<$file2>) { ... do something to get the id $hash{$id}+=3; } close file 2 open 3 output files: the both file, file1 only and file2 only loop back thru file1 and file2 for each line decide where it goes if hash value of the id ==1 file one only if hash value of the id ==3 file two only if hash value of the id ==4 both files negate the hash value to signal that this id has already been dealt with - each id should only appear in one of the 3 output files.
Update:
To just get the id's of the lines into the 3 different files, it is not necessary to read the input files the second time - just dump the hash according to the "rules". In the above, I first thought that each id would be associated with some non-trivial amount of data - that's not true. The above algorithm will run very fast - no sorting/merging is required.

In reply to Re: Help for finding duplicates in huge files by Marshall
in thread Help for finding duplicates in huge files by julio_514

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.