使用sed和/ s提取数字

时间:2019-07-27 03:22:09

标签: sed match

我想用op / s提取值

pgmap 512 pgs:512次有效+清除; 1.39TiB数据,使用4.08TiB,1.15TiB / 5.24TiB可用; 4.43MiB / s wr,46op / s

pginfo="pgmap 512 pgs: 512 active+clean; 1.39TiB data, 4.08TiB used, 1.15TiB / 5.24TiB avail; 4.43MiB/s wr, 46op/s"
echo $pginfo | sed -n '/pgmap/s/.* \([0-9]*\) op\/s.*/\1/p'

但是它不返回任何东西。任何帮助指针将不胜感激。

1 个答案:

答案 0 :(得分:0)

您的正则表达式在数字后寻找空格,但没有空格。

此外,您还应引用已回显的变量以防止其被破坏。

echo "$pginfo" | sed -n '/pgmap/s/.* \([0-9][0-9]*\)op\/s.*/\1/p'