开发者

Optimal solution to extract value from line using Grep

Could you please tell me what is the optimal way to extract idle 开发者_运维技巧value from this line using grep?

CPU states:   0.1% user,   0.1% system,   0.0% nice,  99.8% idle


awk should do the trick:

top -n 1 | grep "idle" | awk '{ print $9 }'

Since the idle-percentage is the ninth value, it's $9.


You can use grep alone:

grep -Po '[0-9.%]+(?= idle)'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜