Issue
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?
Solution
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 string13:
Match literally(
Start a group for the alternatioms27:
Match literally(4[5-9]|5[0-9])
Match 45 - 49 or 50 - 59|
Or28:00
Match literally
)
Close the group
Answered By - The fourth bird Answer Checked By - David Goodson (WPSolving Volunteer)