Skip to content

Instantly share code, notes, and snippets.

@sheeplogh
Created August 22, 2012 02:06
Show Gist options
  • Save sheeplogh/3421464 to your computer and use it in GitHub Desktop.
Save sheeplogh/3421464 to your computer and use it in GitHub Desktop.
grep an accesslog(apache) file within a specific time period
$ cat ACCESS_LOG | awk '$4 >= "[29/Jan/2012:12:00:00" && $4 < "[29/Jan/2012:13:00:00"'
Copy link

ghost commented Jul 20, 2018

works like a charm. Thanks.

@movd
Copy link

movd commented Feb 5, 2019

Works great!

When the time format in the log is like [Tue Feb 05 09:59:54 2019]. It needs to be matched like bellow, because column $4 just contains the time.

Between 9am and 10am:
$ cat ACCESS_LOG | awk '$4 >= "09:00:00 2019" && $4 < "10:00:00"'

@ant-thomas
Copy link

That's great. Is there a quick way to throw a bash variable in there?

eg. yesterday - date +%d/%b/%Y --date="yesterday" - which gives 07/Apr/2019
and today - date +%d/%b/%Y - which gives 06/Apr/2019

@ericsonrumuy7
Copy link

i think that script not valid because the weight of days is larger then weight of years and month

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment