sandy105 has asked for the wisdom of the Perl Monks concerning the following question:
i am trying to process a largish ~50 mb log file ,however with the current code ,its taking way too long
i am basically searching for unique id's in second [] and then looping thru whole file looking for keywords and writing to output file..but its taking hours
my@id; my $date; my $id; my $keyword; my $mess; my @uniqueid; my %seen; #read the file (PLEASE PROVIDE INPUT FILE PATH) open(hanr,"d:/Log.txt")or die"error $!\n"; #digesting the lines @lines = <hanr>; #iterating through the lines foreach $line (@lines) { $line =~ /\[(.+?)\] .* \[(.+?)\] .* \[[^]]+\] \s+ (.*) /x or next +; $id = $2; push (@id , $id); #pushing id to array } #for getting unique user id's foreach $value (@id) { if (! $seen{$value}++ ) { push @uniqueid, $value; } } #OPENING OUTPUT FILE;PROVIDE PATH open (myfile,">D:\\output\\op.txt") or die("error:cannot create $! \n" +); foreach $uniquevalue (@uniqueid) { foreach $line (@lines) { $line =~ /\[(.+?)\] .* \[(.+?)\] .* \[[^]]+\] \s+ (.*) /x or n +ext ; $date = $1; $id = $2; $keyword = $3; if($uniquevalue eq $2 && $keyword eq "Orchestration Started"){ print myfile "$date,$id,$keyword \n"; next; } if($uniquevalue eq $2 && $keyword =~/^Input Message/){ print myfile "$date,$id,"."Input Message to P5 \n"; next; } if($uniquevalue eq $2 && $keyword =~ /^TP Service Request/){ print myfile "$date,$id,"."Service Request \n"; next; } if($uniquevalue eq $2 && $keyword =~/^P5 Move request :/ ){ print myfile "$date,$id,"."Move request \n"; next; } if($uniquevalue eq $2 && $keyword =~/^ProcessName:/){ $mess = substr $keyword , 12; print myfile "$date,$id,$mess \n"; next; } if($uniquevalue eq $2 && $keyword =~/^Process Message :/ ){ my $mess = substr $keyword , 17; print myfile "$date,$id,$mess \n"; next; } } }
the search for unique id's is fast enough , but for the second block ,the if loops are searching for keyword for each unique id thru the WHOLE file.its painfully slow,how can i improve speed ??
ps. as requested a sample of log or exact signature
[2014-06-24 15:10:10,936] DEBUG - [27421b9e-fbd3-11e3-943c-ff89c266c130] [PreProcess] Ended successfully.
[2014-06-24 15:10:10,936] DEBUG - [27421b9e-fbd3-11e3-943c-ff89c266c130] [PreProcess] Orchestration Started
[date]text - [uniqueid][sometext]keyword-egProcessName:
also this is some more information , i dont need the id's in order in output file. and for each unique id like 27421b9e-fbd3-11e3-943c-ff89c266c130 i want to log date , id and "keyword" so i will pickup only the second line above
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: very slow processing
by RonW (Parson) on Aug 20, 2014 at 17:25 UTC | |
by sandy105 (Scribe) on Aug 20, 2014 at 18:37 UTC | |
by RonW (Parson) on Aug 20, 2014 at 23:17 UTC | |
|
Re: very slow processing
by philipbailey (Curate) on Aug 20, 2014 at 19:23 UTC | |
|
Re: very slow processing
by GrandFather (Saint) on Aug 20, 2014 at 21:16 UTC | |
by RonW (Parson) on Aug 20, 2014 at 23:23 UTC | |
by sandy105 (Scribe) on Aug 21, 2014 at 09:33 UTC | |
|
Re: very slow processing
by oiskuu (Hermit) on Aug 21, 2014 at 00:17 UTC | |
by sandy105 (Scribe) on Aug 21, 2014 at 09:51 UTC | |
|
Re: very slow processing
by GrandFather (Saint) on Aug 21, 2014 at 21:10 UTC | |
|
Re: very slow processing
by sandy105 (Scribe) on Aug 21, 2014 at 10:47 UTC |