So, I have the following log sample:
2015-03-30 10:19:44,200 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:ABCD] A log message 1
2015-03-30 10:19:45,250 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:ABCD] A log message 2
2015-03-30 10:19:45,700 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:ABCD] log message of exception occurred in
abc.cdef.class.sdk.SampleException: Message exception..
<stacktrace lines goes here>
2015-03-30 10:19:46,100 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:ABCD] A log message 3
2015-03-30 10:19:46,120 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:ABCD] A log message 4
2015-03-30 10:19:46,120 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d800e80-5276-4006-a44d-dd4cea7bcbe1 Info:P13 Code:AB4D] A log message 6
Each request that comes in the server as a unique IDA. I want to grep all lines of log that have a certain IDA and put in another logfile with all the occurrences found. I’m using grep because it also append the file and line number ( grep –n ) where those patterns were found (the serach goes on 2 ou 3 files). But still, I also want that the stacktrace exceptions to be included, which is not happening because those lines don’t have the IDA that I am searching.
Furthermore that stacktrace exception may also happen as part of the last entry for a specific IDA, like this:
2015-03-30 10:19:44,200 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:ABCD] A log message 1
2015-03-30 10:19:45,200 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:BECD] A log message 2
2015-03-30 10:19:44,200 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:DFCD] A log message 3
2015-03-30 10:19:45,200 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:BBCD] A log message 4
2015-03-30 10:19:45,200 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:ABCC] log message of exception occurred in
abc.cdef.class.sdk.SampleException: Message exception..
<stacktrace lines goes here>
2015-03-30 10:19:45,200 DEBUG [Default : 1] [Application:ABC BIW: IDA:ed8ede83-1116-4697-a69d-ee6cd575cbe7 Info:P23 Code:ABDD] A log message 5
Any suggestions to accomplish this?
P.S.1- I've been searching around, but I've mostle found searches between tags, which in my case is not good enough.
P.S.2-My solution os currently just a one liner grep, but i am open to other solutions, such as perl, awk, sed, python or any other "bash command way to go".