开发者

Optimal solution to extract value from line using Grep

开发者 https://www.devze.com 2023-01-31 23:53 出处:网络
Could you please tell me what is the optimal way to extract idle 开发者_运维技巧value from this 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

精彩评论

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

关注公众号