Created
August 22, 2012 02:06
-
-
Save sheeplogh/3421464 to your computer and use it in GitHub Desktop.
grep an accesslog(apache) file within a specific time period
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat ACCESS_LOG | awk '$4 >= "[29/Jan/2012:12:00:00" && $4 < "[29/Jan/2012:13:00:00"' |
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"'
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
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
works like a charm. Thanks.