Created
January 6, 2020 22:15
-
-
Save chaimleib/c565ee31078b5978dabf46f74f1d9eac to your computer and use it in GitHub Desktop.
Collapse Java stack traces (sed)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sed -n -f | |
### Collapse third-party errors to | |
### at com.thirdparty.theirPackage first error text | |
### ... | |
### at com.thirdparty.theirPackage last error text | |
{ | |
:loop | |
/\t*at com\.evernote/ b print | |
/\t*at .*\..*\./! b print | |
# swap in the hold buffer, which holds our history | |
x | |
# append the current line | |
/^$/! G | |
# without a newline if the history is empty | |
/^$/ g | |
# collapse the history to three lines max | |
s/\n.*\n/\ | |
...\ | |
/ | |
# print the last line regardless | |
$ { | |
# clean up by printing the history (which now includes the current line) | |
p | |
# end the program | |
q | |
} | |
# swap the history back to the hold buffer | |
x | |
# load the next line | |
n | |
b loop | |
### print the previous lines for context | |
# swap in the hold buffer | |
x | |
# and print it if it has anything | |
/^$/ ! p | |
# clear it | |
s/[.\s\n]*// | |
# now swap the current line back in from the hold buffer | |
x | |
:pblock | |
# and print it | |
p | |
# if this was the last line, end the program | |
$ q | |
# otherwise, load the next line | |
n | |
# keep printing lines until we find a 3rd party error again | |
/\t*at com\.evernote/ b pblock | |
/\t*at .*\..*\./ b loop | |
b pblock | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment