regex – grep:组捕获

我有以下字符串:
{"_id":"scheme_version","_rev":"4-cad1842a7646b4497066e09c3788e724","scheme_version":1234}

并且我需要获得“scheme version”的值,在此示例中为1234。

我努力了

grep -Eo "\"scheme_version\":(\w*)"

但是它返回

"scheme_version":1234

如何做到?我知道我可以添加sed调用,但我更喜欢用单个grep。

这可能适合您:
echo '{"_id":"scheme_version","scheme_version":1234}' |
sed -n 's/.*"scheme_version":\([^}]*\)}/\1/p'
1234

对不起,它不是grep,所以如果你喜欢忽略这个解决方案。

或粘贴grep并添加

grep -Eo "\"scheme_version\":(\w*)"| cut -d: -f2

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...