Parse string with bash and extract number

后端 未结 6 1275
猫巷女王i
猫巷女王i 2021-01-04 04:41

I\'ve got supervisor\'s status output, looking like this.

frontend                         RUNNING    pid 16652, uptime 2:11:17
nginx                                


        
6条回答
  •  甜味超标
    2021-01-04 04:57

    assuming that the grep implementation supports the -o option, you could use two greps:

    output \
      | grep -o '^nginx[[:space:]]\+[[:upper:]]\+[[:space:]]\+pid [0-9]\+' \
      | grep -o '[0-9]\+$'
    

提交回复
热议问题