2016-05-30 72 views
1

我想監視應用程序服務器中的一些掛起的線程,並且我得到了這一行。

[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.
在bash中分割字符串

我需要在「There is/0 is thread(s)」中獲得0。
我試圖用cut來分割它,但一切都很糟糕。我也嘗試使用分隔符,但字符串太長。
我該如何拆分它?

回答

1

您可以使用sed捕捉號碼之間 「有/是」 和 「線」,並刪除一切,就像這樣:

sed 's/.*There is\/are \([0-9]\+\) thread.*/\1/' file 
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