Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: dynamic zcat and grep

by johngg (Abbot)
on Mar 21, 2006 at 23:32 UTC ( #538345=note: print w/replies, xml ) Need Help??

in reply to dynamic zcat and grep

You could try installing the Compress::Zlib module and use that to read the log file directly.

use strict; use warnings; use Compress::Zlib; # Set up what we want to match. # our $reg1 = "Joe Sinclair"; our $reg2 = "Bill Halburg"; our $rxNames = qr{(?:$reg1|$reg2)} # Open compressed log file. # our $logFile = "file.gz"; our $gzInput = gzopen($logFile, "rb") or die "gzopen: $gzerrno\n"; # Read line by line into $_ counting bytes read. # our $bytesRead; while($bytesRead = $gzInput->gzreadline($_)) { # Print if it matches. # print if /$rxNames/; } # Check that we have read to the end. Close # file. # die "Incomplete read: $gzerrno\n" unless $gzerrno == Z_STREAM_END; $gzInput->close();

I have not tested this but I have adapted it from a script doing somthing similar.



Replies are listed 'Best First'.
Re^2: dynamic zcat and grep
by clmcshque (Initiate) on Mar 22, 2006 at 00:40 UTC
    Ah yes, without the ability to install the module, I cannot try this, I will however test it on another machine. Thank you for the input.
Re^2: dynamic zcat and grep
by clmcshque (Initiate) on Mar 23, 2006 at 17:26 UTC
    Thanks, I got the module installed, and with a bit of tweaking it all works fine now.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://538345]
[marto]: good morning all
[Corion]: Hi marto!

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2018-06-25 08:29 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.