in reply to Can I regex & grep to select contiguous lines?

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 Re: Can I regex & grep to select contiguous lines?

Replies are listed 'Best First'.
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