You can tell date what format to use for it's output. This is a little less cumbersome that post-processing the output with awk. If you use the same format string as the one found in the log file, you can just use grep to find matches for that day which contain some string.
There are a couple of ways to make the grep statement. Firstly, you can grep the logfile for all messages on the specified date, and then pipe that output into a second grep statement which can filter for the string you are looking for.
By the way $(this) does the same execute-and-use-result substitution as backticks, like `this`. I prefer $(this) because backticks are frequently mis-read, and are not nestable.
Assuming you are interested in today's log messages, you can do it like this:
Code:
grep "^$(date '+%b %e')" /var/log/messages |grep "ata1: command 0x25 timeout"
Note the meaning of %b and %e are documented in the date manual page. %b means the three letter month name abbreviation, and %e means the space padded day of the month.
A second method is to construct a pattern for grep which filters for both the date and the log text of interest. To understand it, you need to know a little about how regular expression patterns work. The "." character in regular expressions means "any character". The "*" character means "the previous expression zero or mor times". Thus you can use ".*" to mean "any combination of characters, or no characters at all". By the way "^", as used in the first solution means "the start of the line".
With this knowledge, you can make an expression which included both the required date filter, and the message pattern:
Code:
grep "^$(date '+%b %e').*ata1: command 0x25 timeout" /var/log/messages
This solution is arguably preferable to the first one in that it invokes only one process (a single grep, as opposed to two instances of grep). As a rule of thumb when shell scripting, the less processes you invoke, the better.