how to grep or egrep pattern of apache access_log file

Hi

I need to look for the range dates of access_log for example:
between 02/May/2009:14:56:20 and 05/May/2009:18:46:06
then write the content to another file. Date and time is very important for me to concatenate them into access_log later.

Thanks

There's an easy solution, but the problem is that it's not exact. To understand what I mean, consider that Apache logs the requests as it completes them, but the date/time is when the request was made. It's therefore possible that extracting such a range will (a) include requests made (but not completed) before the start of that range and/or (b) exclude requests made within the time range but completed after other requests were made. So with that caveat, simply use awk:

awk '/02\/May\/2009:14:56:20/, /05\/May\/2009:18:46:06/' access_log

Oh, and since I deal with HTTP logs on a daily basis, one word of advice: change the custom log format to a tab-delimited one, like this:

LogFormat "%t\t%>s\t%b\t%r" tdf
CustomLog logs/access.tdf tdf 

Obviously, you'll want more information in LogFormat -- this is a quick example. For more info, see Log Files - Apache HTTP Server. The main idea is to separate each field with tabs. From this, you can easily convert to the "Common-log" format if needed, but more importantly, you can more easily handle the logs directly with tools like awk.

awk -F\\t '$2 != 200'

This is very helpful.

Thanks alot!