0

I am trying to fetch logs from log file using grep command and format of log file is as follows:

[1/10/16 23:55:33:018 PST] 00000057 ServerObj E   SECJ0373E: Exception message
at com.own.ws.wim.util.UniqueNameHelper.formatUniqueName(UniqueNameHelper.java:102)
at com.own.ws.wim.ProfileManager.getImpl(ProfileManager.java:1569)

Until now, I am able to fetch logs but I want stack trace as well.

grep -i '^[[:space:]]*at' --before-context=2 SystemOut.log | grep "1/13/16 7:[1-60]" 

output : [1/10/16 23:55:33:018 PST] 00000057 ServerObj E   SECJ0373E: Exception message

Any idea how this can be achieved?

0

Awk with a field separator of "at" can also work. "^[" matches lines starting with the date stamp and $1 is the first field.

awk -F"at" '/^\[/{print $1}' test

Based on your comment and if I understand properly what you need, the awk command should include the lines you are looking for with your grep range between 7 and 8 o'clock.

However, it sounds like you need two lists. To do this you could run the awk command on your log file and output it to another file. You could then awk/grep the second file.

awk -F"at" '/^\[/{print $1}' test>> ExtractedLogs.txt
awk -F"at" '$1 ~ "07:"{print $1}' ExtractedLogs.txt>> StackTraceOnly.txt
  • grep "1/13/16 7:[1-60]" --> This is fetching based on time from 7 to 8 0'clock. So I just want to combine these two filters. – Anil Kumar Jan 14 '16 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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