使用 grep、sed 或 awk 获取 JSON 值
我有一个JSON配置文件,我正在尝试通过以下GREP命令提取值:
grep -oP '"private_key": "\K[^\"]*' config.json
如您所见,我有工作正则是REGEX,但是\ k语法在较旧版本的Regex中不支持。例如,如果将风味切换到Python或Ecmasixt,则正则是不再有效的。我想知道是否还有其他一些语法可以达到相同的结果。
I have a JSON configuration file I'm trying to extract values from via the following grep command:
grep -oP '"private_key": "\K[^\"]*' config.json
As you can see, I have working regex, however the \K syntax is not supported in older versions of Regex. For example, if you switch the flavor to Python or ECMAscript, the regex no longer works. I'm wondering if there's some other syntax to achieve the same result.
https://regex101.com/r/jfGwNT/1
Also, if anyone can think of a better name for this question, please let me know!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
sed
来代替gnu-grep
,如下所示:Instead of
gnu-grep
, you can usesed
like this: