p10.txt
perform testing
Date: Nov-29-2012
Host: amg
Machtype: x86e_win64
mode: 7
ver: 1400
Build : A-01-10
-------------------------------------------------------------------
testcase Version x-20-17
-------------------------------------------------------------------
Retrieve_generic_assembly_(CP) 00:01:23
Retrieve_assembly_1_(CP) 00:01:34
Retrieve_assembly_2_(CP) 00:01:44
-------------------------------------------------------------------
xxx 00:47:03
yyy 00:47:31
************************************************** **
************************************************** **
-------------------------------------------------------------------
ggg Version P-20-17
-------------------------------------------------------------------
Retrieve_generic_assembly_(CP) 00:01:25
Retrieve_assembly_1_(CP) 00:01:35
Retrieve_assembly_2_(CP) 00:01:42
-------------------------------------------------------------------
xxx 00:47:03
yyy 00:47:31
************************************************** **
************************************************** **
-------------------------------------------------------------------
ggg Version P-20-17
-------------------------------------------------------------------
Retrieve_generic_assembly_(CP) 00:01:25
Retrieve_assembly_1_(CP) 00:01:35
Retrieve_assembly_2_(CP) 00:01:42
-------------------------------------------------------------------
pp 00:47:02
kk 00:47:36
************************************************** **
************************************************** **
p20.txt
perform testing
Date: Nov-29-2012
Host: amg
Machtype: x86e_win64
mode: 7
ver: 1400
Build : A-01-10
-------------------------------------------------------------------
testcase Version x-20-17
-------------------------------------------------------------------
Retrieve_generic_assembly_(CP) 00:01:20
Retrieve_assembly_1_(CP) 00:01:32
Retrieve_assembly_2_(CP) 00:01:41
-------------------------------------------------------------------
xxx 00:47:03
yyy 00:47:31
************************************************** **
************************************************** **
-------------------------------------------------------------------
ggg Version P-20-17
-------------------------------------------------------------------
Retrieve_generic_assembly_(CP) 00:01:25
Retrieve_assembly_1_(CP) 00:01:35
Retrieve_assembly_2_(CP) 00:01:42
-------------------------------------------------------------------
xxx 00:47:03
yyy 00:47:31
************************************************** **
************************************************** **
-------------------------------------------------------------------
ggg Version P-20-17
-------------------------------------------------------------------
Retrieve_generic_assembly_(CP) 00:01:25
Retrieve_assembly_1_(CP) 00:01:35
Retrieve_assembly_2_(CP) 00:01:42
-------------------------------------------------------------------
pp 00:47:02
kk 00:47:36
************************************************** **
************************************************** **
I want output.txt file in following format
1- To add and take average of second column entry(time stamp in hh:mm:ss) in file p10.txt (eg Retrieve_generic_assembly_(CP) is coming three times. So add all 3 entry and take average).
Similarly do it for p20.txt.
2- Write a new file output.txt that should have entry for
all first column and avg entry of file p10.txt in second column and avg entry of p20.txt in third column and take difference of second and third column in fourth column.
I want output.txt format like this in 4 column
Subsection P10 P20 Delta(p10-p20)
Retrieve_generic_assembly_(CP) 00:01:25 00:01:26 -00:00:01
Retrieve_assembly_1_(CP) 00:01:35 00:00:45 00:00:50
Retrieve_assembly_2_(CP) 00:01:42 00:02:46 -00:01:04
-----------------------------------------------------------
I am trying to achieve it through following code.
Expand|Select|Wrap|Line Numbers
- my $file1 = 'p10.txt';
- my $file2 = 'p20.txt';
- my $REPORT_FILE = 'outfile.txt';
- my %HoA;
- open (R, $file1) or die ("Could not open $file1!");
- while(<R>){
- chomp;
- my ($k, $v) = split(/\s+/);
- push @{$HoA{'R'}{$k}},$v;
- }
- close(R);
- open (P, $file2) or die ("Could not open $file2!");
- while(<P>){
- chomp;
- my ($k, $v) = split(/\s+/);
- push @{$HoA{'P'}{$k}},$v;
- }
- close(P);
- #print Dumper \%HoA;
- open FILE, ">$REPORT_FILE" or die $!;
- print FILE "Testcase Name P-20-17 P-20-17_system diff\n------------------------------------------------------------------\n";
- foreach my $R (keys %{ $HoA{'R'} }) {
- if (exists $HoA{'P'}{$R}) {
- print FILE "$R";
- foreach my $classR ( @{$HoA{'R'}{$R}} ) {
- foreach my $classP ( @{$HoA{'P'}{$R}} ) {
- printf FILE "\t%-10s%-10s%s\n",$classR,$classP,$classR -$classP;
- }
- }
- print FILE "\n";
- }
- else {
- print FILE "$R";
- foreach my $classR ( @{$HoA{'R'}{$R}} ){
- printf FILE "\t%-10s%-10s%s\n",$classR,"Not Run", "N/A";
- }
- }
- }
- close(FILE);