0

This question already has an answer here:

I want to get log details between two dates but I am unable to print anything with the command:

egrep "^\[MAY 16 11:00:00\]"  alert.log -A 10000 | egrep "^\[MAY 16 16:30:00\]" -B 10000

marked as duplicate by Eric Renouf, Jeff Schaller, Kusalananda, phk, GAD3R May 18 '17 at 19:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • The date is like this Mon May 15 15:32:01 2017 – user3297431 May 18 '17 at 15:51
  • Your date example in the comment here regarding the log file source does not match the case of your example egrep search string. Please clarify if the log actually looks like, or what exactly you want your search string to match. Maybe include a small snippet from the log itself? – FCTW May 18 '17 at 16:10
0

Using sed:

sed -n '/May 16 11:00:00/,/May 16 16:30:00/p' /path/to/inputfile

With grep, I think the problems may be firstly the order of your parameters -- you're putting the -A and -B arguments after the input file, so grep is probably trying to read files called -A, -B, and 10000; and secondly, that you are not escaping your square braces. Your pipeline could work as follows:

grep -E -A10000 'May 16 11:00:00' alert.log | grep -E -B10000 'May 16 16:30:00'

Note that these will only work if you actually have a log entry that matches the exact timestamp for which you are searching; adjust accordingly for the first and last entry you want as the limits of your search.

  • Thanks Dope but your SED does show nothing. The format of date in my TEXT file is like this (Mon May 15 15:32:01 2017). I ran your command and did not get any output – user3297431 May 18 '17 at 16:04
  • Next time compose your question in a manner that reflects what you're searching for; I shall update my answer accordingly. – DopeGhoti May 18 '17 at 16:20
0

Using egrep based on the example you provided:

egrep "May 16 1[1-6]:..:.." /path/to/file | egrep -v "May .. 16:[3-5][1-9]:[0-9][1-9]"
  • Thanks FCTW. But still i am getting nothing. – user3297431 May 18 '17 at 16:11
  • Please clarify the actual log contents as I asked in the comment above. – FCTW May 18 '17 at 16:21
  • Mon May 15 15:32:00 2017 Using deprecated SQLNET.ALLOWED_LOGON_VERSION parameter. Mon May 15 15:32:00 2017 Using deprecated SQLNET.ALLOWED_LOGON_VERSION parameter. Using deprecated SQLNET.ALLOWED_LOGON_VERSION parameter. Using deprecated SQLNET.ALLOWED_LOGON_VERSION parameter. Mon May 15 15:32:00 2017 Using deprecated SQLNET.ALLOWED_LOGON_VERSION parameter. Using deprecated SQLNET.ALLOWED_LOGON_VERSION parameter. Mon May 15 15:32:00 2017 – user3297431 May 18 '17 at 17:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.