Hello,

Currently I'm facing problem with comparing two huges files on a particular key column. One file consists of 10k records and other one 18million records. Both files are | (pipe) delimited. I am comparing based on the first column in the two files and redirecting them to two separate files. If Key columns are same it has to pick the record from 10k records file and send it to one file. If the Key columns are not matching ie., the key column is present in 18 million records file but not in 10k records file, it has to go into another file.

Here I'm pasting the query what I have written, taking more time.

#!/usr/bin/perl $oldFile1 = $ARGV[0]; $newFile1 = $ARGV[1]; $oldFile2 = "unchanged.txt"; $changes1 = "changed.txt"; if (!$oldFile1) { printf("Error: No old file is provided\n"); exit(1); } if (!$newFile1) { printf("Error: No new file is provided\n"); exit(1); } open(OLDFILE1, $oldFile1) or die("Can't open $oldFile1 for input: $!") +; open(NEWFILE1, $newFile1) or die("Can't open $newFile1 for input: $!") +; open(OLDFILE2, ">$oldFile2") or die("Can't open $oldFile2 for output: +$!"); open(CHANGES1, ">$changes1") or die("Can't open $changes1 for output: +$!"); foreach (<OLDFILE1>) { $line1 = $_; chomp $line1; ($x,$y,$z,$a,$b,$c)=split(/\|/,$line1); foreach (<NEWFILE1>) { $line2 = $_; chomp $line2; ($x1,$y1,$z1,$a1,$b1,$c1)=split(/\|/,$line2); if ($x eq $x1) { print OLDFILE2 "$line1\n"; } else { print CHANGES1 "$line2\n"; } } } close(OLDFILE1); close(NEWFILE1); close(OLDFILE2); close(CHANGES1);Hello,
Currently I'm facing problem with comparing two huges files on a particular key column. One file consists of 10k records and other one 18million records. Both files are | (pipe) delimited. I am comparing based on the first column in the two files and redirecting them to two separate files. If Key columns are same it has to pick the record from 10k records file and send it to one file. If the Key columns are not matching ie., the key column is present in 18 million records file but not in 10k records file, it has to go into another file.

Here I'm pasting the query what I have written, taking more time.

#!/usr/bin/perl $oldFile1 = $ARGV[0]; $newFile1 = $ARGV[1]; $oldFile2 = "unchanged.txt"; $changes1 = "changed.txt"; if (!$oldFile1) { printf("Error: No old file is provided\n"); exit(1); } if (!$newFile1) { printf("Error: No new file is provided\n"); exit(1); } open(OLDFILE1, $oldFile1) or die("Can't open $oldFile1 for input: $!") +; open(NEWFILE1, $newFile1) or die("Can't open $newFile1 for input: $!") +; open(OLDFILE2, ">$oldFile2") or die("Can't open $oldFile2 for output: +$!"); open(CHANGES1, ">$changes1") or die("Can't open $changes1 for output: +$!"); foreach (<OLDFILE1>) { $line1 = $_; chomp $line1; ($x,$y,$z,$a,$b,$c)=split(/\|/,$line1); foreach (<NEWFILE1>) { $line2 = $_; chomp $line2; ($x1,$y1,$z1,$a1,$b1,$c1)=split(/\|/,$line2); if ($x eq $x1) { print OLDFILE2 "$line1\n"; } else { print CHANGES1 "$line2\n"; } } } close(OLDFILE1); close(NEWFILE1); close(OLDFILE2); close(CHANGES1);

In reply to comparing two huges files by vamsikrishna

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.