Unix Shell - grep a date-time range

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > March 2006 > grep a date-time range





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author grep a date-time range
Mr_Bill

2006-03-16, 5:53 pm

These files have in them a date and time formated as:

03/16/06 01:16 am

Is there a way for me to grep all files that fall between
03/14/06 and 03/16/06 between 12:00 am and 01:00 am?

Thanks,
Mr_Bill



Stephane Chazelas

2006-03-16, 5:53 pm

On Thu, 16 Mar 2006 14:06:59 GMT, Mr_Bill wrote:
> These files have in them a date and time formated as:
>
> 03/16/06 01:16 am
>
> Is there a way for me to grep all files that fall between
> 03/14/06 and 03/16/06 between 12:00 am and 01:00 am?

[...]

grep -lE '03/1[4-6]/06 (12:[0-5][0-9]|01:00) am' -- *.txt

--
Stephane
Mr_Bill

2006-03-16, 5:53 pm

On Thu, 16 Mar 2006 14:25:04 +0000, Stephane Chazelas wrote:

> [...]
>
> grep -lE '03/1[4-6]/06 (12:[0-5][0-9]|01:00) am' -- *.txt


Thank you so much!

Let me see if I have the syntax straight.
(12:[0-5][0-9]|01:00) uses the () because we used the "|" and
the "|" is, in this case, a logical "or"?

The space between the date and time expressions represents
a logical "and"?

Would tell me, please, what the "--" in -- *.txt does?

Thanks again!
Mr_Bill
Kurt Swanson

2006-03-16, 5:53 pm

Mr_Bill <No_thanks@null_mail.org> writes:
> On Thu, 16 Mar 2006 14:25:04 +0000, Stephane Chazelas wrote:


[vbcol=seagreen]
[vbcol=seagreen]
> Thank you so much!


> Let me see if I have the syntax straight.
> (12:[0-5][0-9]|01:00) uses the () because we used the "|" and
> the "|" is, in this case, a logical "or"?


right...

> The space between the date and time expressions represents
> a logical "and"?


no, that represents a space... the OR'ing is what's in the brackets:
[4-6], for example, represents 4 or 5 or 6.

> Would tell me, please, what the "--" in -- *.txt does?


it says "anything after me is not an option, but a parameter/argument
to grep, in case one of the files starts with a '-'."
--
© 2006 Kurt Swanson AB
Mr_Bill

2006-03-16, 5:53 pm

On Thu, 16 Mar 2006 07:58:55 -0800, Kurt Swanson wrote:

>
> no, that represents a space...


grep -lE '03/1[4-6]/06 (12:[0-5][0-9]|01:00) am' -- *.txt
^
This space

But as soon as I typed that I realized this not a date AND time expression
but a single string that can have possible characters in possible places.

Thanks,
Mr "I feel strangely empowered now" Bill
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com