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