log file grep by date and year
hi guys, how do i use grep on a log file to filter by date and year.
Thanks for any input. |
You need to know the entry and date format in use then write your regex accordingly, grep supports multiple pattern arguments so you'd do something like:
Code:
grep -e <year_regex> -e <day_of_month_regex> /path/to/logfile |
Quote:
if i am on the directory where the log file is located, do I need to specify the path or just the name of the file? |
Whichever you prefer .. normally I would keep scripts in a central location say /usr/local/bin, then use the absolute path.
|
You may find this post unSpawn illuminating.
Date formats vary, but the lesson is there. |
hi guys, I had tried the regex but it just doesn't seem to work.
actually i'm trying to find an exact match for the date 14 Jan 2013, using the commands below: grep '^[14]/Jan/[2013]'+/ path to log grep '^\(14\)?\(Jan\)?\(2013\)' path to log grep '^[14]?[Jan]?[2013]*' path to log log file has this format: [14/Jan/2013 16:38:51] IP address 1.2.3.4 How to do it in regex to find the exact date match? Thanks. |
Code:
grep -e '^\[14\/Jan\/2013.*' /path/to/log |
Quote:
sorry the dot after 2013 followed by * what does it mean? 2013. <--this dot what it means? |
The final .* of the regex is pointless - dot means any character and * means zero or more repetitions of dot. You can end this RE at 2013
|
True .. I think I put it in due to habit, commonly matching different pieces of a line
|
hi guys, thank you so much for all your help!
|
All times are GMT -5. The time now is 09:33 AM. |