X-Git-Url: http://lab.mitty.jp/git/?a=blobdiff_plain;f=misc%2Fregexfilter.pl;fp=misc%2Fregexfilter.pl;h=801cbb04b623f9ffe3e1c9b814e0f348799eabd8;hb=d79589accd6fc8bab3b3d339a47b968b15e09015;hp=0000000000000000000000000000000000000000;hpb=ef43e77722bd7b1e6760a77eea711c232d1ee9fe;p=lab.git 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"; +}