Your first regex and Hash usage may be a challange, so here is a complete program, based on a log that looks like this:
2012-06-01 16:04:46,395 <a href="?node=Thread-12796%20-%20Dispatcher%2 +0thread%20%231">Thread-12796 - Dispatcher thread #1</a> INFO JMaster +Protocol - JMasterProtocol.getMasterPushExitInstance: Asked exit ins +tance for target 'SPF293R' from dispatcher
use strict; use warnings; use diagnostics; my $searchfor = shift @ARGV or die "Please specify the search target a +s an argument"; my (%TargetList, $linecount, @foundThreads); my $logName = 'test-logfile.txt'; open my $logIn, '<', $logName or die "Can't open $logName: $!\n"; while (defined (my $line = <$logIn>)) { $linecount++; my ($thread, $target) = $line=~m/Thread-(\d+).+target\s*'([^']+)'/ +or next; push @{ $TargetList{$thread} }, $target; if ($target eq $searchfor){ push @foundThreads, $thread; } } close $logIn; if (scalar(@foundThreads)>0){ print "Target '$searchfor' is in threads " . join(",",@foundThreads), "\n"; print "Targets in these threads are:\n"; for my $t(sort @foundThreads){ print " $t: $_\n" for @{$TargetList{$t}}; } }else{ print "*** Target '$searchfor' was not found in log $logName\n"; } print "Totals: $linecount lines, ",scalar(keys %TargetList)," Threads. +\n";
UpdateRe-read the specifications, and now display context is slightly different.

             I hope life isn't a big joke, because I don't get it.
                   -SNL


In reply to Re: Parsing a logfile. by NetWallah
in thread Parsing a logfile. by concept

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.