rruser has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: combining 2 files with 4 columns need help
by 2teez (Vicar) on May 29, 2013 at 13:43 UTC | |
by rruser (Acolyte) on May 29, 2013 at 16:52 UTC | |
by rruser (Acolyte) on May 29, 2013 at 18:23 UTC | |
|
Re: combining 2 files with 4 columns need help
by Random_Walk (Prior) on May 29, 2013 at 13:36 UTC | |
|
Re: combining 2 files with 4 columns need help
by poj (Abbot) on May 29, 2013 at 18:19 UTC | |
by rruser (Acolyte) on May 29, 2013 at 19:18 UTC | |
by poj (Abbot) on May 29, 2013 at 19:24 UTC | |
by rruser (Acolyte) on May 29, 2013 at 19:37 UTC | |
by poj (Abbot) on May 29, 2013 at 19:39 UTC | |
|