Command line 使用grep在命令行中显示特定值

Command line 使用grep在命令行中显示特定值,command-line,grep,Command Line,Grep,我必须检查一个产品的许可证,我只需输入即可 checklicence 在命令行中 它给了我输出: Product License status Parameters of license Sxxxxx--xxxxx--xxxxx4 Volume Regular texts Units: Pages Quantity: 120000 per year Remains: 107852 this year 我想知道还有多少剩余的,然后

我必须检查一个产品的许可证,我只需输入即可

checklicence 
在命令行中

它给了我输出:

Product License status

Parameters of license Sxxxxx--xxxxx--xxxxx4


Volume
    Regular texts
        Units: Pages
        Quantity: 120000 per year
        Remains: 107852 this year
我想知道还有多少剩余的,然后打印出来

所以我试着去做

 >checklicense |grep -i "Remains:"
我得到的输出是

>Remains: 107852 this year
但我只想把数字
107852
作为输出

有没有办法做到这一点

我的grep版本是
许可证GPLv3+:GNU GPL版本3

Checklicense |grep -i "Remains:" | grep -o "[0-9]*"

这将只获得第一个grep结果的数字部分,您可以使用GNU grep中的
-p
标志以及
-o
标志仅匹配我们正在寻找的部分

checklicence | grep -oP 'Remains:\s\K([^ ]\d+)'
107852
GNU grep
中的
-p
标志用于启用库

\K:


另外值得一提的是,
mangrep
页面上说

这是高度实验性的,
grep-p
可能会警告未实现的特性


@Inian
许可证GPLv3+:GNU GPL版本3
请在下面找到我的答案,并告诉我它是否解决了您的问题grep-o的功能可能重复?-o仅显示与特定格式匹配的部分,因为只需要数字[0-9]*通配符