source: lab/trunk/misc/regexfilter.pl @ 184

Last change on this file since 184 was 184, checked in by mitty, 11 years ago
  • read text file/stdin and check each line with multiple regex
  • Property svn:executable set to *
File size: 676 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");
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, "\n";
42}
Note: See TracBrowser for help on using the repository browser.