I need to be able to match the first field (car number) to the date in both files. Either file my have multiple listing of the date. If no date exists it still gets written out. If multiple dates I really need to match the closest dates to each other. (ex. 04/01/2013 04/05/2013 then 04/06/2013 04/30/2013) I hope this makes sense. Thanks for any help

I can't figure out how to combine my two files to get the desired output.

file 1: AOKX 495408, L, 04/02/13, SWCOMP AOKX 495408, L, 04/20/13, SWCOMP BLHX 102, L, 04/01/13, WILDCOM CRDX 7067, L, 04/05/13, TYCO WW 9030, L, 04/02/13, HALLI file2: AOKX 495408, L, 04/15/13, SWCOMP BLHX 102, L, 04/03/13, WILDCOM BLHX 102, L, 04/30/13, WILDCOM CRDX 7067, L, 04/20/13, TYCO WW 9030, L, 04/30/13, HALLI output (what it needs to look like) $key $le $date $rdate $company or $rcompany AOKX 495408 L 04/02/13 04/15/2013 SWCOMP AOKX 495408 L 04/20/13 SWCOMP BLHX 102 L 04/01/13 04/03/2013 WILDCOM BLHX 102 L 04/30/2013 WILDCOM CRDX 7067 L 04/05/13 04/20/2013 TYCO WW 9030 L 04/02/13 04/30/13 HALLI #!/usr/bin/perl # use strict; use warnings; open FILE1, "<", "out1.txt" or die "$!\n"; my %hash; while ( <FILE1> ) { chomp $_; my ( $key, $le, $date, $company ) = split ',', $_; $hash{$key} = [$le, $date, $company]; # print "$key $date\n"; } close FILE1; open FILE2, "<", "out2.txt" or die "$!\n"; open OUTFILE, ">", "final.txt" or die "$!\n"; while (<FILE2>) { my ( $rkey, $rle, $rdate, $rcompany ) = split ',', $_; $hash{$rkey} = [$rle, $rdate, $rcompany]; # print OUTFILE "\n"; #to write out once figure out how to combine } close FILE2; close OUTFILE;

In reply to combining 2 files with 4 columns need help by rruser

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.