Search code examples
linuxgrep

Linux: grep for multiple strings in a log file on a certain date


Sorry for a seemingly frequently asked question, but the other thread answers did not work for me. The log I am trying to search through is formatted like so:

Jul 24 23:11:08 TG-12345 gateway [words] Tools 987654321 Join request

I want to grep the log found in /var/etc/messages for all instances of the date, let's say 'Jul 24' in this case, and '987654321'. What is the proper instruction to do this? Thank you.

EDIT: though not necessary, if you know how to also throw in a timeframe (the hour, not the date) in the same search, that would be great; but I do need at least the date and tool# working first. Thanks again.


Solution

  • Just use the command twice:

    grep 'Jul 24' <filename> | grep '987654321'