in reply to Re^2: using system command in regex
in thread using system command in regex
my $SMPP_count = int ((split (/\s+/,`cut -d "|" -f 1,10,13 SMSCDR*$ +date$hour$minute*.log |grep "Submit|GSM" |grep "$hour:$min:$sec" |sor +t |uniq -c`)) [1]) + int ((split (/\s+/,`cut -d "|" -f 1,10,13 SMSCDR +*$date$hour$minute*.log |grep "Submit|SMPP" |grep "$hour:$min:$sec" | +sort |uniq -c`)) [1]);
Short answer: since you are using uniq -c as the last filter in you pipelines, you are interested in the first field. This field has leading whitespace. From the documentation of split:
As another special case, "split" emulates the default behavior of the command line tool awk when the PATTERN is either omitted or a literal string composed of a single space character (such as ' ' or "\x20", but not e.g. "/ /"). In this case, any leading whitespace in EXPR is removed before splitting occurs, and the PATTERN is instead treated as if it were "/\s+/"; in particular, this means that any contiguous whitespace (not just a single space character) is used as a separator.
Long answer: you are running
From your code I am guessing that your log files contain a timestamp in the first field, Submit occurs in the 10th field, and you want lines which contain GSMor SMPP in the 13th field.
Putting it all together, omitting uneccesary steps and not writing perl as if it were shell:
update: corrected code@ARGV = glob "SMSCDR*$date$hour$minute*.log"; my $SMPP_count; my $stamp = "$hour:$min:$sec"; while(<>){ chomp; my @ary = (split '|')[0,9,12]; $SMPP_count++ if $ary[0] eq $stamp and $ary[1] eq "Submit" and $ary[2] =~ /(GSM|SMPP)/; }; print $SMPP_count;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: using system command in regex
by ravi45722 (Pilgrim) on Oct 14, 2015 at 05:46 UTC | |
by shmem (Chancellor) on Oct 15, 2015 at 07:51 UTC | |
by ravi45722 (Pilgrim) on Oct 15, 2015 at 10:41 UTC | |
by marto (Cardinal) on Oct 15, 2015 at 10:47 UTC | |
by shmem (Chancellor) on Oct 15, 2015 at 12:24 UTC | |
by ravi45722 (Pilgrim) on Oct 16, 2015 at 03:59 UTC | |
| |
by soonix (Chancellor) on Oct 15, 2015 at 14:48 UTC | |
by shmem (Chancellor) on Oct 15, 2015 at 15:33 UTC | |
| |
by shmem (Chancellor) on Oct 14, 2015 at 17:48 UTC | |
by ravi45722 (Pilgrim) on Oct 15, 2015 at 04:08 UTC |