How to remove(filter out) specific Java Stack-Traces from output in Linux?

Sebastien Diot :

Our Maven build produces lots of Java Stack-Traces when running the tests. On our build-server, I would like to filter some of those out, specifically, those that look like:

javax.naming.NameNotFoundException: some.name.blabla
    at ...
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:XXX)

to reduce the size of the output. If a test fails, we can always rerun the tests locally, to get the full output.

I would like to do this, without changing anything to our code or our Maven build files; I want to just pipe the Maven output into some Linux shell commands, that filter out those Stack-Traces.

So far, I have only found questions/answers that want to extract/capture them, or filter them using changes in Java code, or Maven, or Eclipse, or that filter away all Stack-Traces.

Ivan :

For a test file like this

$ cat file
str1
javax.naming.NameNotFoundException: some.name.blabla
    at ...
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:XXX)
str2
javax.naming.NameNotFoundException: some.name.blabla
    at ...
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:XXX)
str3

Using sed

$ sed '/NameNotFoundException/,/ForkedBooter/d' file
str1
str2
str3

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=216461&siteId=1