Below is my log structure
0317 09:53:14.865+0000 {12772} INFO [pm-worker-exec slot-Task:id=8274 +,env=12772,type=11][c.s.w.t.f.s.PostExecutionStage ] Loaded {child r +unId vs completion type}: {8286-SUCCESSFUL}{8287-SUCCESSFUL}{8288-SUC +CESSFUL}{8289-SUCCESSFUL}{8290-SUCCESSFUL}{8291-SUCCESSFUL}{8292-SUCC +ESSFUL}{8293-SUCCESSFUL}{8294-SUCCESSFUL}{8295-SUCCESSFUL}{8296-SUCCE +SSFUL} 0317 09:54:12.498+0000 {12772} INFO [pm-worker-exec slot-Task:id=8273 +,env=12772,type=55][edProcessInputBatchKafkaProducer] Started produci +ng records on topic 12772_8286_20170317_IN_0 0317 09:54:13.428+0000 {12772} INFO [pm-worker-exec slot-Task:id=8273 +,env=12772,type=55][edProcessInputBatchKafkaProducer] Started produci +ng records on topic 12772_8287_20170317_IN_0 0317 09:55:13.027+0000 {12772} INFO [pm-worker-exec slot-Task:id=8273 +,env=12772,type=55][edProcessInputBatchKafkaProducer] Done with produ +cing records on topic 12772_8286_20170317_IN_0 0317 09:55:15.027+0000 {12772} INFO [pm-worker-exec slot-Task:id=8273 +,env=12772,type=55][edProcessInputBatchKafkaProducer] Done with produ +cing records on topic 12772_8287_20170317_IN_0

So in above log structure first I need to fetch all successful child runID(i.e 8286,8287....8296) for parent id 8274.Now for each runID i have to get started producing records time stamp and done with producing records time stamp

I tried below logic but thats messed up.Could you please help me regarding this logic

desired output is below

topic,start_time,Endtime 12772_8286_20170317_IN_0,09:54:12.498+0000,09:55:13.027+0000 12772_8287_20170317_IN_0,09:54:13.428+0000,09:55:15.027+0000

Below is my code

open (MYFILE, '>data.CSV'); $LOGFILE = "worker.log"; open(LOGFILE) or die("Could not open log file."); $LOGFILE1 = "worker.log"; open(LOGFILE1) or die("Could not open log file."); $taskid=8274; foreach $line (<LOGFILE>) { chomp($line); if ( $line =~ m/$taskid.*child runId vs completion type/) { @Task_id = $line =~ /\{(\d+)-/g; } } foreach $line (<LOGFILE1>) { chomp($line); foreach $childid(@Task_id) { if ( $line =~ m/Started producing records on topic (\d+)_($childid +)_(\d+)_IN_(\d+)/) { $envId=$1; $timestamp=$3; $input=$4; my @fields = split / /, $line; $data1="$envId\_$childid\_$timestamp\_IN\_$input\,$fields[1]"; $data2="$envId\_$childid\_$timestamp\_IN\_$input"; push @data9,$data1 ; print "$data1\n"; } if ( $line =~ m/Done with producing records on topic (\d+)_($chil +did)_(\d+)_IN_(\d+)/) { $envId=$1; $timestamp=$3; $input=$4; my @fields = split / /, $line; $data3="$envId\_$childid\_$timestamp\_IN\_$input\,$fields[1]"; $data4="$envId\_$childid\_$timestamp\_IN\_$input"; push @data9,$data3 ; print "$data3\n"; } } } foreach (@data9) { print MYFILE "$_\n"; } close LOGFILE; close LOGFILE1;

In reply to Log Parsing by piyushmnnit06

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.