Skip to content

Instantly share code, notes, and snippets.

@chaimleib
Created January 6, 2020 22:15
Show Gist options
  • Save chaimleib/c565ee31078b5978dabf46f74f1d9eac to your computer and use it in GitHub Desktop.
Save chaimleib/c565ee31078b5978dabf46f74f1d9eac to your computer and use it in GitHub Desktop.
Collapse Java stack traces (sed)
#!/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
:print
# 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