【问题标题】:Split string in bash在bash中拆分字符串
【发布时间】:2016-05-30 19:11:27
【问题描述】:

我正在尝试监视应用程序服务器中的一些挂起线程,我得到了这条线。

[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.

我需要在“有/有 0 个线程”中获取 0。
我尝试使用 cut 将其拆分,但一切都一团糟。我也尝试使用分隔符,但字符串太长。
怎么拆分?

【问题讨论】:

    标签: regex linux string bash shell


    【解决方案1】:

    您可以使用sed 捕获“There is/are”和“thread”之间的数字并删除其他所有内容,如下所示:

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

    【讨论】:

      【解决方案2】:
      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
      

      【讨论】:

        猜你喜欢
        • 2013-01-15
        • 1970-01-01
        • 1970-01-01
        • 2016-05-30
        • 2011-10-30
        • 1970-01-01
        • 1970-01-01
        • 2021-10-23
        • 2013-08-08
        相关资源
        最近更新 更多