Re: data manipulation
From: Bob (bNOoONb_at_not.pilbara.net.au)
Date: 10/10/03
- Next message: Jorge Barrios: "Re: every combination of letters"
- Previous message: Iain Truskett: "Re: Opinions on "new SomeObject" vs. "SomeObject->new()""
- In reply to: Gunnar Hjalmarsson: "Re: data manipulation"
- Next in thread: Gunnar Hjalmarsson: "Re: data manipulation"
- Reply: Gunnar Hjalmarsson: "Re: data manipulation"
- Reply: Tad McClellan: "Re: data manipulation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Jorge Barrios: "Re: every combination of letters"
- Previous message: Iain Truskett: "Re: Opinions on "new SomeObject" vs. "SomeObject->new()""
- In reply to: Gunnar Hjalmarsson: "Re: data manipulation"
- Next in thread: Gunnar Hjalmarsson: "Re: data manipulation"
- Reply: Gunnar Hjalmarsson: "Re: data manipulation"
- Reply: Tad McClellan: "Re: data manipulation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|