* read text file/stdin and check each line with multiple regex
authormitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Thu, 3 Jan 2013 15:33:44 +0000 (15:33 +0000)
committermitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Thu, 3 Jan 2013 15:33:44 +0000 (15:33 +0000)
git-svn-id: https://lab.mitty.jp/svn/lab/trunk@184 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

misc/regexfilter.pl [new file with mode: 0755]

diff --git a/misc/regexfilter.pl b/misc/regexfilter.pl
new file mode 100755 (executable)
index 0000000..801cbb0
--- /dev/null
@@ -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";
+}