1

I'm trying to monitor some hung threads in an application server and I got this line.

[5/30/16 11:31:18:501 CDT] 00000655 ThreadMonitor W WSVR0606W: Thread "MessageListenerThreadPool : 38" (00000655) was previously reported to be hung but has completed. It was active for approximately 964450 milliseconds. There is/are 0 thread(s) in total in the server that still may be hung.

I need to obtain the 0 in "There is/are 0 thread(s)".
I tried to split it using cut, but everything was a mess. I also tried to use a delimiter, but the string is too long.
How can I split it?

2 Answers 2

1

You can use sed to capture the number between "There is/are " and " thread" and remove everything else, like this:

sed 's/.*There is\/are \([0-9]\+\) thread.*/\1/' file
Sign up to request clarification or add additional context in comments.

Comments

0
sed -nr 's/.*are ([0-9]+) thread.*/\1/p' file

-r, --regexp-extended
use extended regular expressions in the script.

-n, --quiet, --silent
suppress automatic printing of pattern space

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.