我正在和JQ合作,到目前为止我非常喜欢它.我遇到了一个问题,我还没有找到其他地方的解决方案,并希望看看社区是否有办法做到这一点.
我们假设我们有一个看起来像这样的JSON文件:
{"author": "Gary", "text": "Blah"}
{"author": "Larry", "text": "More Blah"}
{"author": "Jerry", "text": "Yet more Blah"}
{"author": "Barry", "text": "Even more Blah"}
{"author": "Teri", "text": "Text on text on text"}
{"author": "Bob", "text": "Another thing to say"}
Run Code Online (Sandbox Code Playgroud)
现在,我们想要选择值author等于"Gary"或"Larry"的行,但没有其他情况.实际上,我有几千个我正在检查的名字,所以简单地陈述直接或条件(例如cat blah.json | jq -r 'select(.author == "Gary" or .author == "Larry")')是不够的.我试图通过inside像这样的函数来做到这一点,但得到一个错误对话框:
author
cat blah.json | jq -r 'select(.author == "Gary" or .author == "Larry")'
做这样的事情最好的方法是什么?