Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: File Search And Compare

by PyroX (Pilgrim)
on Feb 19, 2002 at 18:14 UTC ( [id://146410]=note: print w/replies, xml ) Need Help??


in reply to File Search And Compare

Thanks Everyone, here is the final product, which seems to be working very well so far.

#!/usr/bin/perl -w use strict; $|++; use FileHandle; my $FILE = new FileHandle; open($FILE,"<","/var/log/$ARGV[0]") or die "ERROR: can't open file! $! +"; my $pattern = 'fw1'; my (%parsed, $i); while(<$FILE>){ if(/$pattern/i && $i++){ my $z=0; my $out=""; chomp $_; @new=split(/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/,$_); foreach $piece (@new){ $z++; chomp $piece; $out.="$piece"; } @new=split(/service/,$out); $out=$new[0]; print "$out\n"; } } close($FILE);


Thanks Again!

Replies are listed 'Best First'.
Re: Re: File Search And Compare
by petral (Curate) on Feb 20, 2002 at 18:51 UTC
    Except one small oops:    $i++   returns 0 on the first post-increment, so the    if (/pat/ && ...   fails the first time a line matches. update My oops! That seems to be what you want, or something like it.   Your original seemed to look for duplicate _full_ lines.   But nevermind...

      p

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://146410]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-25 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found