Re: data manipulation

From: Bob (bNOoONb_at_not.pilbara.net.au)
Date: 10/10/03


Date: Fri, 10 Oct 2003 13:10:37 +0930


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:bm3848$i2lpa$1@ID-184292.news.uni-berlin.de...
> Bob wrote:
> > I have a log file i want to further manipulate, and be able to
> > extract info from.
> >
> > (the actual output data is from qmail-qread command )
> >
> > the format of the file is as below
> >
> > 6 Oct 2003 14:01:12 GMT #23456 12345 <email@fake.com>
> > remote somone@fake.com
> > done someonelse@fake.com
> > 6 Oct .....
> >
> > the format is always date, line, followed by 1 or more info lines,
> > that are either \t or " " indented.
> >
> > I want to grap each of these "chunks" and then run a regex and
> > output them when I get a match.
> >
> > So, using the data I have, I want to read in the (3 lines in this
> > case, but can 2 to ???? lines) and then output the whole block if I
> > match a regex.
> >
> > If anyone can recommend some place to start reading It would be
> > appreciated.
>
> http://learn.perl.org/
>
> I'm quite sure that you were able to figure that out yourself, though,
> and that you actually wanted somebody to write some code, without
> having given it a try yourself first. :( I'd be surprised if there
> weren't better ways, but this is one possible approach:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my ($chunk, @chunks);
> open FH, 'logfile' or die $!;
> while (<FH>) {
> if (/^\S/) {
> push @chunks, $chunk if $chunk;
> $chunk = '';
> }
> $chunk .= $_;
> }
> close FH;
> push @chunks, $chunk;
>
> # print chunks that include the domain fake.com
> print grep { /\@fake\.com/ } @chunks;
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>

Thanks for the assistance, I was able to use most of what you offered with
what I already had.

I am new to Perl, and after reading, there are only 2 lines I don't clearly
understand

-> push @chunks, $chunk if $chunk;
-> $chunk = '';

After reading the push function description from "learning Perl" I am
failing to understand exactly what is happening here.

B



Relevant Pages

  • Re: about sysclean from trend micro (Rusty & Marcy)
    ... 2005-01-12, 15:21:41, Could not set file for reading on ... you OS is clean based upon what Sysclean and Pattern File 335 could find. ... Just attach the LOG file here. ...
    (microsoft.public.security.virus)
  • Re: Novice::Help>Split IP Address(port) + count
    ... log file: What is the best combination of 'split' and regexes to do ... But the code you posted starts with opening and reading the file -- ... which is not your stated problem. ... dealing with printing the results of your line parsing to STDOUT -- ...
    (comp.lang.perl.misc)
  • Re: rebuffering an opened file
    ... > I am openeing a log file for processing (I need to look for certain ... > would like the file pointer to be positioned where i stopped reading. ... > to reread the file and thus see the changes. ...
    (comp.lang.c)
  • data manipulation
    ... I have a log file i want to further manipulate, and be able to extract info ... (the actual output data is from qmail-qread command) ... I want to grap each of these "chunks" and then run a regex and output them ...
    (comp.lang.perl.misc)
  • Re: data manipulation
    ... > I have a log file i want to further manipulate, ... > extract info from. ... > the format is always date, line, followed by 1 or more info lines, ...
    (comp.lang.perl.misc)