Search code examples
regexjvmjstack

How to remove this lines in the middle?


I have dump JVM thread from a server. From the dump, I'd like to erase some line using regex.

    at java.lang.Thread.run(Thread.java:722)

   Locked ownable synchronizers:
    - <0x00000005b8052b20> (a java.util.concurrent.ThreadPoolExecutor$Worker)

"catalina-exec-126" daemon prio=10 tid=0x00007f7b58ac5800 nid=0x4171 runnable [0x00007f7ac4800000]

I want the output to be like this

    at java.lang.Thread.run(Thread.java:722)

"catalina-exec-126" daemon prio=10 tid=0x00007f7b58ac5800 nid=0x4171 runnable [0x00007f7ac4800000]

Does anyone have an idea how to do this using regex? Because the value is dynamic. Please suggest


Solution

  • It seems that you made a thread dump.

    You can try this awk one-liner to modify your dump file:

    awk -v RS="\n\n" -v ORS="\n\n" '!/Locked ownable synchro/' yourDump > newDump
    

    btw, this is not a java question, although your input file was created by jstack.