sed command to extract stacktraces
Hi,
I'm trying to extract stacktraces from log files, looking for the pattern "Exception". If a line contains "Exception", a stack trace will follow in multiple lines. If the next line begins with a timestamp entry in the format "[1/13/10 23:17:00:444 CST]", the stack trace has ended in the previous line. Additionally, I want to grab the nearest line containing a timestamp entry above the original line that contained the pattern "Exception". Sometimes it's on the same line and other times it's a few lines above it. How I do write a sed command for this? Example: Code:
[1/13/10 23:01:16:623 CST] 00000059 SystemOut O 2010-01-13 23:01:16,623 [ORB.thread.pool : 0] INFO Thanks. |
Hi -
The good news is that sed supports "start patterns" (along with corresponding "stop patterns"). For example: Quote:
http://www.grymoire.com/Unix/Sed.html <= Search for "ranges by patterns" If you've got a clearly delimited block (for example, "start" through "stop", or "Exception" through "INFO"), then you've got it made. Otherwise, this might be a good time to start learning Perl or Python ;). 'Hope that helps .. PSM PS: Even though "awk" is a lot more powerful than "sed", I don't think it would necessarily buy you that much for this problem. You've either got a nice, straightforward text pattern (in which case "sed" should be OK), or you need procedural logic (in which case I'd recommend looking at a scripting language like Perl or Python). |
@OP, you did not show your desired output, so here's a guess of what you want.
Code:
awk '/^\[/{f=1;g=0;o=$0} |
Quote:
|
Hey Ghostdog74 ... like the above, would it be possible to explain how it works?
I am not quite sure how the setting of your f and g variables are producing the desired result? (Hope this isn't a stupid question) |
Yes, I have been able to make some progress -
Code:
sed -n '/Exception/,/\[.* .* CST\].*$/p' SystemOut.log a) I need to exclude the last line containing timestamp entry b) I need to get the first line containing the timestamp entry, resulting in - Code:
[1/13/10 23:01:16:623 CST] 00000059 SystemOut O 2010-01-13 23:01:16,623 [ORB.thread.pool : 0] INFO Quote:
|
All times are GMT -5. The time now is 11:06 AM. |