If both files are 500M you probably don't want to read them all into memory to work on them (unless you've got over a gig of RAM and/or swap handy). If you know that lines in the different files are always going to match up (line 25 in file one always corresponds to line 25 in file two):

open( ONE, "file1" ) or die "open file1: $!"; open( TWO, "file2" ) or die "open file2: $!"; open( OUT, ">merged" ) or die "open merged: $!"; while( <ONE> ) { chomp; my $two = <TWO>; print OUT $_, (split( " ", $two ))[-1], "\n" } close( ONE ); close( TWO ); close( OUT );

If you can't guarantee a one-to-one mapping between lines, then you probably want to look into using DB_File or the like to generate a hash on disk of the second file key'd by the first two columns (assuming that's what relates the values from the two different files). Then you'd read through the first file and pull the corresponding value from the hash.


In reply to Re: merging to databases... Should be easy... by Fletch
in thread merging to databases... Should be easy... by Anonymous Monk

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.