【发布时间】:2017-08-17 14:53:35
【问题描述】:
我有一个带有多个值输出的字符串,如下所示:
SD performance read=1450kB/s write=872kB/s no error (0 0), ManufactorerID 27 Date 2014/2 CardType 2 Blocksize 512 Erase 0 MaxtransferRate 25000000 RWfactor 2 ReadSpeed 22222222Hz WriteSpeed 22222222Hz MaxReadCurrentVDDmin 3 MaxReadCurrentVDDmax 5 MaxWriteCurrentVDDmin 3 MaxWriteCurrentVDDmax 1
我想使用 bash 和 sed 仅输出读取值 (1450kB/s)。 我试过了
sed 's/read=\(.*\)kB/\1/'
但输出 read=1450kB 但我只想要数字。 感谢您的帮助。
【问题讨论】:
-
你得到的输出看起来不正确.. 例如:
echo 'SD performance read=1450kB/s write=872kB/s no error' | sed 's/read=\(.*\)kB/\1/'将给出SD performance 1450kB/s write=872/s no error -
只获取号码,试试
sed 's/.*read=\([0-9]*\)kB.*/\1/' -
如果您需要
awk,请使用此awk '{print $3}' test.txt | awk -F "=" '{print $2}' -
这正是我想要的,谢谢!