Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Answer: Can I regex & grep to select contiguous lines?

( #192584=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > Can I regex & grep to select contiguous lines? contributed by sauoq

As your lines are in chronological order anyway, it doesn't make sense to use grep. A grep will search through the whole array but you want a set of contiguous entries and as soon as you find one outside of the right interval you know you are done searching.

You would be better off simply iterating through the lines. If seconds don't matter at all, you can just look at the last digit of your minutes and once that digit mod 5 is the same as your starting digit, you are done.

If seconds do matter, you'll have to do a little more work but the principle of iterating though the lines instead of grepping still holds.

Comment on Answer: Can I regex & grep to select contiguous lines?
Re: Answer: Can I regex & grep to select contiguous lines?
by blakem (Monsignor) on Aug 24, 2002 at 21:13 UTC
    once that digit mod 5 is the same as your starting digit, you are done
    That assumes there is at least one entry for each minute... What if the log looked like:
    2:00:00 all is well 2:01:00 all is well 2:02:00 all is well 2:03:00 all is well 2:04:00 oops, reboot 2:21:00 all is well again
    I think looking at more than just that one digit is wise.

    -Blake

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 imbibing at the Monastery: (2)
As of 2014-10-02 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (49 votes), past polls