Link to home
Start Free TrialLog in
Avatar of k3vsmith

asked on

grep for a current date in a particular format

This is RHEL 5 os. I'm using bsh.
I am trying to grep a log for the current date.
The way the log records the date is in this format:

How do I grep for the current day and month? The rest of the date doesn't matter.

So far this is my command:
grep page.jsp /path_to_log/access.log | grep 404

Id like to include only to search for todays date as I dont care about past dates.

Thanks in advance.
Avatar of woolmilkporc
Flag of Germany image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of k3vsmith


Thanks for the response but that doesn't seem to work. I still get all dates, not just today's date.
Hold on, confirming that I actually have a date of todays date in file, if not will add one and try again
So try

grep ^`date "+%d/%b/"` /path_to_log/access.log
Ok, yes its working. I dont have any with todays date. Threw me off at first. Thanks!
If there is no date of todays date in file then you should have seen no output at all.

Please try the above "backtick" version, if needed without the caret.