On Fri, Jun 20, 2003 at 08:21:52AM -0600, Warren Block wrote:
> On Fri, 20 Jun 2003, Matthew Seaman wrote:
> 
> > > Or if anyone has a perl script that tosses out the odd
> > > lines and just keeps the full lines and is willing to
> > > share it, that would work too. Otherwise, I am going
> > > to have to get better at perl in a big way.
> >
> >     #!/usr/bin/perl -w
> >
> >     $prevline = "";
> >
> >     while (<>) {
> >         if (m/last message repeated (\d+) times/) {
> >             for ( 1 .. $1 ) {
> >                 print $prevline;
> >             }
> >         } else {
> >             print $_;
> >             $prevline = $_;
> >         }
> >     }
> 
> If I read that right, this would also work:
> 
> #!/usr/bin/perl -w
> 
> while (<>) {
>       print $_ unless $_ =~ /last message repeated (\d+) times/;
> }

That's not quite the same thing.  You're just taking out the lines
that match /last message repeated \d+ times/ (and constructing a
backreference to \d+ that you never use):

    Jun 20 16:26:02 example /kernel: ipfw: 800 Deny TCP 12.34.56.78:1234 
21.43.65.87:4321 out via de0
    Jun 20 16:26:27 example last message repeated 2 times

becomes:

    Jun 20 16:26:02 example /kernel: ipfw: 800 Deny TCP 12.34.56.78:1234 
21.43.65.87:4321 out via de0

whereas I'm replacing that line with the correct number of repeats of
the original line, so the example becomes:

    Jun 20 16:26:02 example /kernel: ipfw: 800 Deny TCP 12.34.56.78:1234 
21.43.65.87:4321 out via de0
    Jun 20 16:26:02 example /kernel: ipfw: 800 Deny TCP 12.34.56.78:1234 
21.43.65.87:4321 out via de0
    Jun 20 16:26:02 example /kernel: ipfw: 800 Deny TCP 12.34.56.78:1234 
21.43.65.87:4321 out via de0

Of course, on closer reading, your code is exactly what the OP asked for.

        Cheers,

        Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to