#!/usr/bin/perl use strict; use warnings; # which file is to be checked my $file = shift @ARGV; die "no input file!\n" unless defined $file; # check with which regex my $regex = qr/error.*error/; # open file for reading open my $fh, '<', $file or die "$file: $!\n"; # try to match regex in file's content if ( ! grep { m/$regex/ } <$fh> ) { # nothing matched; rewind to file's beginning seek $fh, 0, 0 or die "can't reposition on filehandle!\n"; # process file linewise while ( my $line = <$fh> ) { # process file as desired print $line; } close $fh; } # regex matched; don't process file else { close $fh; die "error matched!\n"; } __END__
In reply to Re: match a word then exit
by linuxer
in thread match a word then exit
by ktl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |