Reputation: 2669
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?
Upvotes: 1
Views: 443
Reputation: 98921
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
Upvotes: 0
Reputation: 124646
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
Upvotes: 1