Entering edit mode
8.8 years ago
rajal2
•
0
I need some help to query a result to print out in a .txt file. The result is, by matching two tables in File1.txt
and File2.txt
.
For example, matching Rev ID
from File1.txt
with File2.txt
, say PROD_2_1
, the result should print to an output file all the Rev IDs after and including that Rev, such as PROD_2_1
, PROD_2_2
, its corresponding PROD ID and the Date Released.
This is File1.txt, File2.txt, and my code, which does not print all the Rev IDs after that version. Can you please help me where my code is failing?
File 1
Name PROD ID Rev ID tag version ProjectName
fusetop 9903420 PROD_2_5 SERIALPROD2V9 BXTE0PRODRTL2V2 PROJP
doshrl2top 9903340 PROD_2_3 SERIALPROD1V6 BXTE0PRODRTL1V PROJP
c73p1avrpg 99036247 PROD_2_1 SERIALPROD1V1 BXTE0PRODRTL1V1 PROJP
c73p1 99034236 PROD_2_2 SERIALPROD1V1 BXTE0PRODRTL1V1 PROJP
150top 99034238 PROD_2_2 SERIALPROD1V1 BXTE0PRODRTL1V1 PROJP
familyewp 99033482 PROD_2_3 SERIALPROD1V21 BXTE0PRODRTL1V121PROJP
File 2
Type Name Rev ID PROD ID PROD GROUP Date Released PROD Category Project IDs
IComponent c73p1avrpg PROD_2_2 99036247 SEG 3/3/2015 3:34 Hard
IComponent c73p1avrpg PROD_2_1 99036247 SEG 11/15/2014 18:41 Hard
IComponent c73p1avrpg PROD2_0 99036247 SEG 9/22/2014 1:36 Hard
IComponent c73p1avrpg PROD_1_1 99036247 SEG 6/12/2014 23:51 Hard
IComponent c73p1avrpg PROD_1_0 99036247 SEG 4/8/2014 11:05 Hard
My code:
#!/bin/env perl
use strict;
use warnings;
my $file1 = "FILE1.txt";
my $file2 = "FILE2.txt";
my $OUTPUT = "OUTPUT.txt";
my %results = ();
open FILE1, "$file1" or die "Could not open $file1 \n";
while(my $matchLine = <FILE1>) {
$results{$matchLine} = 1;
}
close(FILE1);
open FILE2, "$file2" or die "Could not open $file2 \n";
while(my $matchLine =<FILE2>) {
$results{$matchLine} = 2 if $results{$matchLine}; #Only when already found in file1
}
close(FILE2);
open (OUTPUT, ">$OUTPUT") or die "Cannot open $OUTPUT \n";
foreach my $matchLine (keys %results) {
print OUTPUT $matchLine if $results{$matchLine} ne 1;
}
close OUTPUT;