Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: using system command in regex

by AppleFritter (Vicar)
on Oct 13, 2015 at 12:07 UTC ( [id://1144682]=note: print w/replies, xml ) Need Help??


in reply to Re^2: using system command in regex
in thread using system command in regex

Don't do everything in one huge unreadable line; break it up, and take a look at what the intermediate steps produce, and I'm sure the problem will become much clearer.

FWIW if you're processing log files using cut, grep, sort, uniq etc., you can probably also read and process them in your Perl script instead. Doing that would also be more robust, more readable/maintainable, and (if log formats change) more future-proof.

Replies are listed 'Best First'.
Re^4: using system command in regex
by ravi45722 (Pilgrim) on Oct 13, 2015 at 13:09 UTC

    At first I started to read the file and processing. But why I choose these path is

     Tue Oct 13 00:00:01 2015|1008|959788857688|123580|Tue Oct 13 00:00:01 2015|Tue Oct 13 00:00:01 2015|CMT|Undelivered|none|Submit|0|SMSC_PR_LC_SMSC_InvalidDestAddress|GSM|INVALID|16 Bit|140|140|no||no|no||1/2|No|NO|no|no|0|1|0|0||959790000028||8|0||0|no|no|default_billing|-1|0|no|no|1|1|1|1|0|1|0|0|||||Wed Oct 14 00:00:01 2015|SR|||IV|011809614446710010008|||0|0||0|0||0||||123580||||||||||||||||||

    This is one line of my log. If you Maximise the zero element  Tue Oct 13 00:00:01 2015 the date & time is available. Like this I have files for each ten minutes.

    SMSCDR_PREPAY_151013000000_10.84.0.29_AS.log (From 00:00:01 to 00:10:0 +0) SMSCDR_PREPAY_151013100000_10.84.0.29_AS.log (From 00:10:01 to 00:20:0 +0) SMSCDR_PREPAY_151013200000_10.84.0.29_AS.log SMSCDR_PREPAY_151013300000_10.84.0.29_AS.log SMSCDR_PREPAY_151013400000_10.84.0.29_AS.log SMSCDR_PREPAY_151013500000_10.84.0.29_AS.log (From 00:50:01 to 01:00:0 +0)

    Like this we have POSTPAID_CDR & DELIVERY_CDR for every 10 minutes as like mentioned above

    Now my requirement is

    00:10:00= 0 0 00:10:01= 158 158 00:10:02= 163 321 00:10:03= 214 535 00:10:04= 123 658 00:10:05= 174 832 00:10:06= 271 1103 00:10:07= 96 1199 00:10:08= 263 1462 00:10:09= 72 1534 00:10:10= 190 1724

    The first element is time. The total after "=" is total entries noted in that particular second where 10th field (Submit) & 13 th field (GSM)in all prepay, postpaid, delivery CDR's. The last one is total entries upto that second from starting of the file.

    And finally I need the highest entries noted in which second & that count

    For that I written code like this

    my @low_sec = ("00","01","02","03","04","05","06","07","08","09"); my @high_sec = (10 .. 59); my @seconds = (@low_sec,@high_sec); my $greatest = 0; my $total = 0; foreach my $min ($minute .. $minute+9) { foreach my $sec (@seconds) { my $SMPP_count = int ((split (/\s+/,`cut -d "|" -f 1,1 +0,13 SMSCDR*$date$hour$minute*.log |grep "Submit|GSM" |grep "$hour:$m +in:$sec" |sort |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]); if ($SMPP_count > $greatest) { $greatest = $SMPP_count; } $total = $total + $SMPP_count; print "$hour:$min:$sec","= $SMPP_count","\t",$total,$/ +; } } print $greatest,$/;

    Is there any easier method please guide me

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1144682]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-24 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found