I have a log file with every line that starts with the following date format.
2020-06-21 12:39:49 enginestart [INFO] total records found
I want to fetch logs dated from 2020-06-15 to 2020-06-21 and to display as output.
I have tried to grep, egrep, and sed and getting the expected result.
grep -E "2020-06-19|2020-06-20" logfile.* > file1
But the above-fetched log only from 20th
Thank you
grep
? Somehow I don't see how something likegrep - P '^2020-06-(1[56789]|2[01])'
would not work?! ... could you please edit your question and include what you have tried? Then we can figure out exactly why it didn't work ... – 0xC0000022L Jun 22 '20 at 8:02-h
. Theman grep
manual is your friend. The lines in your log file do not start with 2020 then? Because my regex anchors it at the beginning of the line (the^
). – 0xC0000022L Jun 22 '20 at 8:33grep -E
line you gave is lacking()
to group the alternatives. I'm not sure it will work without. But the fact that yourgrep -E
invocation and mygrep -P
command both only show output from the 20th makes me think that you may want to look at the files. Also if some of the log files have been compressed (e.g..gz
suffix), grep will typically ignore them except when told otherwise. – 0xC0000022L Jun 22 '20 at 8:35