If you load the current files 50,000 records into a hash keyed by the first field, it will consume ~50MB. That is if you only extract the key and store the entire record as the value:

my %current; open CURRENT, '<', $currentFile or die $!; m[^ ( [^|]+ ) \| ]x and $current{ $1 } = $_ while <CURRENT>; close CURRENT;

If you pre-split the entire record and store the fields as an array, the memory consumption goes way up. So don't do that :)

Then you can process the master file 1 line at a time, extracting the key and looking it up in the hash. When a matching key is found, you then split both records into the fields, compare the required six and take the appropriate action according to the result.

Altogether it might look something like the following pseudo-code. Note: I didn't really understand your description of what you need to do if the records do or dont match so I took you "file X" and "file Y" literally for this example code:

#! perl -slw use strict; my $currentFile = 'current.dat'; my $masterFile = 'master.dat'; my $matched = 'matched.dat'; my $nomatch = 'nomatch.dat'; my %current; open CURRENT, '<', $currentFile or die $!; m[^ ( [^|]+ ) \| ]x and $current{ $1 } = $_ while <CURRENT>; close CURRENT; open X, '>', $matched or die $!; open Y, '>', $nomatch or die $!; open MASTER, '<', $masterFile or die $!; while( <MASTER> ) { if( m[^ ( [^|]+ ) \| ]x and exists $current{ $1 } ) { my $key = $1; my @master = split '\|', $_; my @current = split '\|', $current{ $key }; if( 6 == grep{ $current[ $_ ] eq $master[ $_ ] } 7, 14, 21, 30 +, 50, 119 ) { print X; ## Matched records } else { print Y; ## non-matched records } } } close MASTER; close X; close Y;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: how to find differences between two huge files by BrowserUk
in thread how to find differences between two huge files by sayeevamsi

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.