source: lab.git/misc/regexfilter.pl

Last change on this file was 5a32926, checked in by mitty <mitty@…>, 11 years ago
  • output matched pattern with "/PATTERN/"

git-svn-id: https://lab.mitty.jp/svn/lab/trunk@185 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

  • Property mode set to 100755
File size: 765 bytes
Line 
1#! /usr/bin/perl -w
2
3use warnings;
4use strict;
5
6use Regexp::Assemble;
7
8if ($#ARGV + 1 < 1) {
9    print "$0: list_of_regex [filter_target]\n";
10    exit 0;
11}
12
13my $regexfile = shift @ARGV;
14if (! -r $regexfile) {
15    warn "$0: cannot read '$regexfile'";
16    exit 1;
17}
18
19my $re = Regexp::Assemble->new(file => "$regexfile", track => 1);
20
21my $target = shift @ARGV;
22
23my $input;
24unless (defined($target) and -f $target) {
25    print STDERR "read from STDIN\n";
26    $input = *STDIN;
27}
28else {
29    open $input, "<$target";
30}
31
32my $line;
33while ($line = <$input>) {
34    chomp $line;
35    if ($re->match($line)) {
36        print "OK: ";
37    }
38    else {
39        print "NG: ";
40    }
41    print $line;
42    if ($re->source) {
43        print " /", $re->source, "/";
44    }
45    print "\n";
46}
Note: See TracBrowser for help on using the repository browser.