hiradhu has asked for the wisdom of the Perl Monks concerning the following question:
I have to parse thro the files and get only xml names and the first number next to Process Request for each xml. My code for that goes like this10/22/2008 00:22:01 Start testing --- File: Open Mode: Single Use +r, RPVersion: 2 10/22/2008 00:22:01 Start ------- 1:1:11002_CustomerAdd_WithNotes_R +q.xml 10/22/2008 00:22:04 New QBXMLRP 0.328 65.03 0.00 0.00 10/22/2008 00:22:06 OpenConnection 1.031 65.03 0.00 0.0 +0 10/22/2008 00:22:08 BeginSession 0.453 65.03 0.00 0.00 10/22/2008 00:22:14 ProcessRequest 4.984 65.46 0.43 0.8 +3 10/22/2008 00:22:15 EndSession 0.016 65.46 0.00 0.00 10/22/2008 00:22:15 End --------- 1:1:11002_CustomerAdd_WithNotes_R +q.xml 10/22/2008 00:22:15 Start ------- 1:1:11004_AccountAdd_1_Rq.xml 10/22/2008 00:22:16 BeginSession 0.031 65.46 0.00 0.00 10/22/2008 00:22:17 ProcessRequest 0.422 65.57 0.10 0.5 +9 10/22/2008 00:22:18 EndSession 0.000 65.57 0.00 0.00 10/22/2008 00:22:18 End --------- 1:1:11004_AccountAdd_1_Rq.xml 10/22/2008 00:22:18 Start ------- 1:1:11007_EmployeeAdd_Rq.xml 10/22/2008 00:22:20 BeginSession 0.094 65.57 0.00 0.00 10/22/2008 00:22:21 ProcessRequest 0.766 65.55 -0.02 0. +88 10/22/2008 00:22:22 EndSession 0.016 65.55 0.00 0.00 10/22/2008 00:22:22 End --------- 1:1:11007_EmployeeAdd_Rq.xml
while (<INPUT>) { chomp($_); # Look for title line if ($_ =~/Start -/) { my @sdk_line = split(/\t/, $_); push(@temp, substr($sdk_line[1], 18)); } }
I have to write this to a OUTPUT file in this format. SU1, SU2 are values from files su1_file.txt, su2_file.txt. Which are tab seperated files. The output should also be tab seperated so that I can open in xls.while (<INPUT>) { chomp($_); # find process time for that title if ($_ =~/Process/) { print split(/\t/, $_), "\n"; my @sdk_line = split(/\t/, $_); push(@temp , $sdk_line[2]); } }
I have hardcoded my script to parse only 3 files. How do I do it for multiple/unknown number of files... This is my code.Request Name SU1 SU2 SU3 SU-Avg MU1 MU2 MU3 + MU-Avg 11002_CustomerAdd_WithNotes_Rq.xml 4.984 6.766 6.766 2.645 + 2.141 6.125 6.766 3.006 11004_AccountAdd_1_Rq.xml 0.422 1.203 1.203 0.404 0.297 + 1.062 1.203 0.512 11007_EmployeeAdd_Rq.xml 0.766 0.359 0.359 0.212 0.250 + 0.281 0.359 0.178
## Get the XML names ## sub GetXMLNames { open(INPUT, $inputPath); my @temp_xml = (); while (<INPUT>) { chomp($_); # Look for title line if ($_ =~/Start -/) { my @sdk_line = split(/\t/, $_); push(@temp, substr($sdk_line[1], 18)); } } close INPUT; return @temp; } ## Get the Process time ## sub GetOnlyProcessTime{ open(LOG,">>$parseSDKPerfResultsLog"); open(INPUT, $inputPath); my @temp =(); while (<INPUT>) { chomp($_); # find process time for that title if ($_ =~/Process/) { my @sdk_line = split(/\t/, $_); push(@temp , $sdk_line[2]); } } my $number = scalar(@temp); if($number < $Total_number_of_requests){ my $missing = $Total_number_of_requests - $number; print LOG "$missing request(s) in $inputPath have not got exec +uted. Hence exiting.\n"; close LOG; close INPUT; exit; } close INPUT; return @temp; } ## Parse all the logs ## sub parseSDKPerfmonLogs{ open(LOG,">>$parseSDKPerfResultsLog"); for( my $su=1; $su <= $su_files; $su++){ $su_inputfile = "su".$su."_sdkperfmonlog.txt"; push(@su_inputfile,$su_inputfile); } for( my $mu=1; $mu <= $mu_files; $mu++){ $mu_inputfile = "mu".$mu."_sdkperfmonlog.txt"; push(@mu_inputfile,$mu_inputfile); } #############Get the Request file names in the first column ###### +####### $inputPath=$ResFolderPath."\\su".$su_files."_sdkperfmonlog.txt"; @xml_names = GetXMLNames($inputPath); $Total_number_of_requests = @xml_names; ############# end of Get the request names in results file ####### +################### #############Get the SU process time ############# foreach $sufile (@su_inputfile){ #print $sufile; $inputPath=$ResFolderPath."\\".$sufile; $filenumber = substr($sufile,2,1); @temp = GetOnlyProcessTime($inputPath); if($filenumber <= $su_files){ if( $filenumber == 1){@su_first = @temp; } elsif($filenumber == 2){@su_second = @temp; } elsif($filenumber == 3){@su_third = @temp; } } } #############End of Get the SU process time ############# #############Get the MU process time ############# foreach $mufile (@mu_inputfile){ #print $sufile; $inputPath=$ResFolderPath."\\".$mufile; $filenumber = substr($mufile,2,1); @temp = GetOnlyProcessTime($inputPath); if($filenumber <= $mu_files){ if( $filenumber == 1){@mu_first = @temp; } elsif($filenumber == 2){@mu_second = @temp; } elsif($filenumber == 3){@mu_third = @temp; } } } #############End of Get the MU process time ############# #############Write everything to the output file ############# open(OUTPUT, ">>$outputFile") ; for(my $i = 0; $i < $Total_number_of_requests; $i++){ my $su_average = sprintf("%.3f", (($su_first[$i] + $su_second[ +$i] + $su_third[$i])/$su_files)); my $mu_average = sprintf("%.3f",(($mu_first[$i] + $mu_second[$ +i] + $mu_third[$i])/$mu_files)); print(OUTPUT "$xml_names[$i]\t$su_first[$i]\t$su_second[$i]\t$ +su_third[$i]\t$su_average\t$mu_first[$i]\t$mu_second[$i]\t$mu_third[$ +i]\t$mu_average \n"); } print LOG "All the values from performance logs are available in +$outputFile \n "; close OUTPUT; #############End of Write everything to the output file ########## +### }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing many files and output to one file. Pls HELP
by GrandFather (Saint) on Nov 11, 2008 at 07:48 UTC | |
|
Re: Parsing many files and output to one file. Pls HELP
by moritz (Cardinal) on Nov 11, 2008 at 07:21 UTC | |
by hiradhu (Acolyte) on Nov 11, 2008 at 08:55 UTC | |
by moritz (Cardinal) on Nov 11, 2008 at 09:14 UTC | |
|
Re: Parsing many files and output to one file. Pls HELP
by Cristoforo (Curate) on Nov 11, 2008 at 21:17 UTC | |
by hiradhu (Acolyte) on Nov 13, 2008 at 09:22 UTC | |
|
Re: Parsing many files and output to one file. Pls HELP
by sanku (Beadle) on Nov 12, 2008 at 06:52 UTC |