Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

G'day spikeinc,

Here's a technique for doing what you want.

I couldn't find any instances of 12:15 in the data you provided; I've used 15:13 as it did appear a few times. You may want localtime instead of the gmtime I've used here (you didn't specify your requirements in this regard). The JSON decoding was straightforward. Check the Time::Piece documentation to see how I've used it and for ways to format the output (if that's what you want).

#!/usr/bin/env perl -l use strict; use warnings; use JSON; use Time::Piece; my $wanted_hour = 15; my $wanted_minute = 13; my $data = decode_json join '' => map { chomp; $_ } (<DATA>); for (@{$data->{aaData}}) { print "@$_" if is_wanted_time(@$_[0,1]); } sub is_wanted_time { for (@_) { my $t = gmtime $_; return 1 if $t->hour == $wanted_hour && $t->min == $wanted_min +ute; } return 0; } __DATA__ {"DisplayRecords":"12","Records":"12","sColumns":"startTime,endTime, remoteNode,srcIP,srcPort,destIP,destPort,egress,ingress","aaData":[["1 +375976271" ,"1375976430","LAN","D0:05:FE","172.20.30.2",1093,"172.20.28.2",1330," +1034,348", "0,0"],["1375976246","1375976404","LAN","D0:05:FE","172.20.30.2",1092, +"172.20.28 .2",1327,"1034,348","0,0"],["1375976191","1375976381","LAN","D0:05:FE" +,"172.20.3 0.2",1091,"172.20.28.2",1324,"1034,348","0,0"],["1375976171","13759763 +14","LAN", "D0:05:FE","172.20.30.2",1090,"172.20.28.2",1321,"1034,348","0,0"],["1 +375976144" ,"1375976302","LAN","D0:05:FE","172.20.30.2",1089,"172.20.28.2",1319," +1034,348", "0,0"],["1375975155","1375976089","LAN","D0:05:FE","172.20.30.2",1085, +"172.20.28 .2",1278,"1034,348","0,0"],["1375975194","1375975352","LAN","D0:05:FE" +,"172.20.3 0.2",1086,"172.20.28.2",1281,"1034,348","0,0"],["1375974693","13759748 +35","LAN", "D0:05:FE","172.20.30.2",1083,"172.20.28.2",1271,"1034,348","0,0"],["1 +375974668" ,"1375974827","LAN","D0:05:FE","172.20.30.2",1081,"172.20.28.2",1268," +1034,348", "0,0"],["1375974691","1375974821","LAN","D0:05:FE","172.20.30.2",1082, +"172.20.28 .2",1270,"0,0","0,0"],["1375881371","1375881561","LAN","D0:05:FE","172 +.20.30.2", 1055,"172.20.28.2",1122,"1034,348","0,0"],["1375881410","1375881540"," +LAN","E0:0 5:AE","172.20.30.2",1056,"172.20.28.2",1125,"0,0","0,0"]]}

Output:

$ pm_epoch_from_json.pl 1375974693 1375974835 LAN D0:05:FE 172.20.30.2 1083 172.20.28.2 1271 1 +034,348 0,0 1375974668 1375974827 LAN D0:05:FE 172.20.30.2 1081 172.20.28.2 1268 1 +034,348 0,0 1375974691 1375974821 LAN D0:05:FE 172.20.30.2 1082 172.20.28.2 1270 0 +,0 0,0

-- Ken


In reply to Re: Epoch based parser by kcott
in thread Epoch based parser by spikeinc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (7)
    As of 2015-07-08 03:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (93 votes), past polls