I'm trying to parse lines between a date range in a file. However dates are formatted in a non standard way. Is it possible for a regex to match these? The log file is formatted like so:
Jan 5 11:34:00 log messages here
Jan 13 16:21:00 log messages here
Feb 1 01:14:00 log messages here
Feb 10 16:32:00 more messages
Mar 7 16:32:00 more messages
Apr 21 16:32:00 more messages
For example if I want to match lines between January 1st and Feb 10th, Ive been unable to get regex to match the month order since they arent numerical.
The following shell line, might do the trick. Assume you want to see the first 41 days after January '2nd', then you can do
pipeline of
echo
,date
andgrep
:I believe this is the quickest. The idea is to build a set of possible days (these are the first two lines), and then search for them with
grep
.sorted log-file with
awk
:When processing sorted log-files you can use quick-returns to limit yourself to processing the only-needed fractions.
unsorted log-file with
awk
:When processing unsorted log-files, you need to do the comparisons actively. This obviously takes much more time.
The above commands both return :
note: date-ranges that cross the 31st of December might give bogus results.