Combining regex in grep
I have logs that look like as follows:
Some IP ... Some Text ... [Sep/03/2011:15:55:30 -Some Number]... Some Text... End of Line Some IP ... Some Text ... [Sep/03/2011:18:45:27 -Some Number]... Some Text... End of Line Some IP ... Some Text ... [Sep/03/2011:21:46:00 -Some Number]... Some Text... End of Line I want to "grep" lines for the hours between 16:00:00 and 22:00:00 only. So these two lines of "grep" work fine for me: Code:
grep -hE ':1[6789]:[0-9][0-9]:[0-9][0-9]:*' data.log I have tried these methods: Code:
grep -hE ':1[6789]:[0-9][0-9]:[0-9][0-9]:* \| :2[01]:[0-9][0-9]:[0-9][0-9]:*' data.log Code:
grep -hE ':1[6789]\|2[01]:[0-9][0-9]:[0-9][0-9]:*' data.log So, is there any way to say: I want to "grep" piece of data from lines containing hours values preceded by a : and followed by a : and found in the form of HH:MM:SS (24 hours clock) and the time I am interested in is between 16 and 22 only irrespective of any Minutes and Seconds in between. |
Hi,
Quote:
Try this: Code:
grep -hE '(:1[6789]:[0-9][0-9]:[0-9][0-9]:*|:2[01]:[0-9][0-9]:[0-9][0-9]:*)' data.log Code:
egrep "(foo|bar)" file |
Quote:
Thanks Druuna! I had tried parentheses (|) before also but not sure what I missed out that caused an error on the production box. Only now I found that I had not quoted the pattern: Code:
[demo@localhost Bash]$ grep -E :(1[6789]|2[12]):[0-9][0-9]:[0-9][0-9].* sample.log Code:
[demo@localhost Bash]$ cat sample.log Code:
':(1[6789]|2[01]):[0-9][0-9]:[0-9][0-9].*' |
All times are GMT -5. The time now is 11:15 PM. |