Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Log Parsing

by poj (Abbot)
on Apr 02, 2017 at 19:08 UTC ( [id://1186742]=note: print w/replies, xml ) Need Help??


in reply to Log Parsing

Rather than iterating through an array to find a match like this

foreach $line (<LOGFILE1>) { chomp($line); foreach $childid (@Task_id) {

build a hash and use the keys to match

#!/usr/bin/perl use strict; my %data = (); my @id = (); my $reqid = '8274'; my $infile = 'worker.log'; my $outfile = 'data.CSV'; open IN,'<',$infile or die "$!"; # input while (<IN>) { chomp; next unless /Task:id=(\d+)/; my $taskid = $1; my (undef,$timestamp,undef) = split /\s+/,$_,3; if (/(Started|Done).+topic (\d+_(\d+)_.+)/){ $data{$3}{$1} = $timestamp; $data{$3}{'Topic'} = $2; } while ( /\{(\d+)-SUCCESSFUL\}/g ){ push @id,$1 if ($taskid eq $reqid); } } close IN; # output open OUT,'>',$outfile or die "$!"; my @cols = qw(Topic Started Done); printf OUT "%s,%s,%s\n",@cols; for my $id (sort @id){ if (exists $data{$id}){ printf OUT "%s,%s,%s\n", map { $data{$id}{$_} } @cols; } else { print OUT "$id - no data\n"; } } close OUT;
poj

Replies are listed 'Best First'.
Re^2: Log Parsing
by piyushmnnit06 (Novice) on Apr 03, 2017 at 05:56 UTC
    its working fine but only problem is its providing timing for topics where 1 is appended not 0 .I mean its giving timing for 12772_8287_20170317_IN_1 but not for 12772_8287_20170317_IN_0.

      Make this regex more specific

      #if (/(Started|Done).+topic (\d+_(\d+)_.+)/){ if (/(Started|Done).+topic (\d+_(\d+)_\d+_IN_0)/){
      poj
        Thanks I tried if (/(Started|Done).+topic (\d+_(\d+)_\d+_IN_[0-1])/) but it is working either for 0 or for 1 but I want it to work with both.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1186742]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found