regex - Print string without sub-string in Perl -
i have logfile has format looks this:
[time] [mmm] [data] [rule] [a.a.a.a] [time] [ppp] [data] [rule] [a.a.a.a] [time] [mmm] [data] [rule] [c.c.c.c]
in cant' find way print string without specific sub-string. want able print whole string output without sub-string line matches [mmm]
, [a.a.a.a]
. final output be:
[time] [ppp] [data] [rule] [a.a.a.a] [time] [mmm] [data] [rule] [c.c.c.c]
do use index module 2 subtrings or use grep in someway? looking @ wrong way? appreciated!!!
in perl script have section searches , prints section string:
sub section { @event_rule = ("a", "b", "c"); foreach (@event_rule) { $result1 = `fgrep -h 'data' $logfile1 | grep "$_" | head -n10`; if (length $result1) { print "$result1\n"; } } }
no need external programs grep
:
#!/usr/bin/perl use warnings; use strict; @rule = ('[mmm]', '[a.a.a.a]'); $regex = join '.*', map quotemeta, @rule; # create 1 regular expression "rules". $regex = qr/$regex/; # compile it. $c = 0; while (<>) { $c += print if /data/ && ! /$regex/; last if $c > 9; # print first 10 lines. }
Comments
Post a Comment