Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Searching pattern through log file

Expand Messages
  • merlyn@stonehenge.com
    ... Nilesh I want to search each pattern string and show it only once and count it Nilesh as number of times occurred. Nilesh This is what I have so far my
    Message 1 of 2 , Mar 22, 2005
    • 0 Attachment
      >>>>> "Nilesh" == <Nilesh.Shirodkar@...> writes:

      Nilesh> I want to search each pattern string and show it only once and count it
      Nilesh> as number of times occurred.
      Nilesh> This is what I have so far

      my @patterns = ("Lexical", "Fixing trailing slash", "RPS");
      @ARGV = qw(/users/wib/nileshs/scripts/wwwdynamo.log);

      my %count; # not sure if you want total counts, or counts per file
      my %pat = map { $_ => qr/$_/ } @patterns;

      while (<>) {
      for my $pat (sort keys %pat) {
      if (/$pat{$pat}/) { # seen on this line
      unless ($count{$pat}++) { # not seen before
      print "$pat seen in $_";
      }
      }
      }

      if (eof) {
      print "total lines in $ARGV is $.\n";
      close ARGV; # resets $.
      }
      }

      for (sort keys %counts) {
      print "$_ => $counts{$_}\n";
      }


      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
    Your message has been successfully submitted and would be delivered to recipients shortly.