From: mitty Date: Thu, 3 Jan 2013 15:33:44 +0000 (+0000) Subject: * read text file/stdin and check each line with multiple regex X-Git-Url: http://lab.mitty.jp/git/?a=commitdiff_plain;h=d79589accd6fc8bab3b3d339a47b968b15e09015;p=lab.git * read text file/stdin and check each line with multiple regex git-svn-id: https://lab.mitty.jp/svn/lab/trunk@184 7d2118f6-f56c-43e7-95a2-4bb3031d96e7 --- diff --git a/misc/regexfilter.pl b/misc/regexfilter.pl new file mode 100755 index 0000000..801cbb0 --- /dev/null +++ b/misc/regexfilter.pl @@ -0,0 +1,42 @@ +#! /usr/bin/perl -w + +use warnings; +use strict; + +use Regexp::Assemble; + +if ($#ARGV + 1 < 1) { + print "$0: list_of_regex [filter_target]\n"; + exit 0; +} + +my $regexfile = shift @ARGV; +if (! -r $regexfile) { + warn "$0: cannot read '$regexfile'"; + exit 1; +} + +my $re = Regexp::Assemble->new(file => "$regexfile"); + +my $target = shift @ARGV; + +my $input; +unless (defined($target) and -f $target) { + print STDERR "read from STDIN\n"; + $input = *STDIN; +} +else { + open $input, "<$target"; +} + +my $line; +while ($line = <$input>) { + chomp $line; + if ($re->match($line)) { + print "OK: "; + } + else { + print "NG: "; + } + print $line, "\n"; +}