用bash解析字符串并提取数字 [英] Parse string with bash and extract number
本文介绍了用bash解析字符串并提取数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有主管的状态输出,看起来像这样.
I've got supervisor's status output, looking like this.
frontend RUNNING pid 16652, uptime 2:11:17
nginx RUNNING pid 16651, uptime 2:11:17
redis RUNNING pid 16607, uptime 2:11:32
我需要提取nginx的PID.我已经通过grep -P命令完成了此操作,但是在远程计算机上grep的构建没有perl正则表达式的支持.
I need to extract nginx's PID. I've done it via grep -P command, but on remote machine grep is build without perl regular expression support.
看起来sed或awk正是我所需要的,但是我并不熟悉它们.
Looks like sed or awk is exactly what I need, but I don't familiar with them.
在此先感谢您帮助我找到一种方法.
Please help me to find a way how to do it, thanks in advance.
推荐答案
sed 's/.*pid \([0-9]*\).*/\1/'
这篇关于用bash解析字符串并提取数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文