0

I want to grep log between 13:27:45 - 13:28:00, I managed to grep log between 13:27 - 13:28 with the command grep '^13:2[7-8] logfilename, but how can I grep 13:27:45 - 13:28:00?

Would you recommend using sed or even awk for such operation?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
w97802
  • 109
  • 6
  • Does [this](https://stackoverflow.com/questions/23697958/how-to-search-for-lines-in-a-file-between-two-timestamps-using-bash) answer your question? – tink Nov 27 '22 at 16:38
  • I think this question is about programming or software development. There is a `grep` example with a regex in the question and it has a grep tag. – The fourth bird Dec 05 '22 at 14:48

1 Answers1

2

To match the format 13:27:45 - 13:28:00

grep "^13:\(27:\(4[5-9]\|5[0-9]\)\|28:00\)" file

Or

grep -E "^13:(27:(4[5-9]|5[0-9])|28:00)" file

Explanation

  • ^ Start of string
  • 13: Match literally
  • ( Start a group for the alternatioms
    • 27: Match literally
    • (4[5-9]|5[0-9]) Match 45 - 49 or 50 - 59
    • | Or
    • 28:00 Match literally
  • ) Close the group
The fourth bird
  • 154,723
  • 16
  • 55
  • 70