From d79589accd6fc8bab3b3d339a47b968b15e09015 Mon Sep 17 00:00:00 2001 From: mitty Date: Thu, 3 Jan 2013 15:33:44 +0000 Subject: [PATCH] * 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 --- misc/regexfilter.pl | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 misc/regexfilter.pl 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"; +} -- 1.7.9.5