You're viewing a comment by Robby and its responses.

Robby Permalink
September 28, 2010, 00:06

This comment is a little older, but I found it as a challenge none-the-less and decided to take a crack at it & post my results in case somebody later had the same question. As a bonus (& to make it more useful for myself), it prints the line number above each exception. Here is my result:

sed -e :b -e '/Exception/!d;=;n;:a' -e '/^\[/bb' -e 'n;ba'

Brief explanation in steps:
1. :b set a label to go back to the beginning. i had to use a label, b/c i wanted to be able to go back to the beginning w/o reloading the pattern space.
2. /Exception/!d start over w/ the next line unless we find the word Exception.
3. = print out the line number
4. n print out the current line and load the next line
5. :a set another label for looping over the body of the exception
6. /^\[/bb go back to the beginning if we find a line starting with a bracket. i didn't see a need to expand the regex to match the full timestamp.
7. n;ba print out the current line and loop back to label a

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "floppy_95": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.