我在linux终端上运行libsvm,由一个c程序调用。好的,我需要选择输出,但是格式如下
Accuracy = 80% (24/30) (classification)
我只需要选择“80”作为整数。我和塞德一起试过了,然后来到这个命令:
sed 's/[^0-9^'%']//g' 'f' >> f
这是过滤输出中的所有整数,因此,现在还不能工作,所以我需要帮助。提前谢谢
最佳答案
在PCRE模式(grep
)下尝试-P
,仅打印匹配的部分(-o
),使用alookahead assertion:
$ echo "Accuracy = 80% (24/30) (classification)" | grep -Po '[0-9]+(?=%)'
80
regexp:
[0-9] # match a digit
+ # one or more times
(?=%) # assert that the digits are followed by a %