JQ:过滤结果不包含字符串OR小于值

时间:2018-03-11 22:35:57

标签: json select jq

在Ubuntu上,我有

jq '.[] | {addr: .addr, subver: .subver, inbound: .inbound, synced_blocks: .synced_blocks} | select(.synced_blocks < 77982)'

{
  "addr": "299.247.7.254:8268",
  "subver": "/String:0.22.5.7/",
  "inbound": false,
  "synced_blocks": 77979
}
{
  "addr": "228.290.206.224:8268",
  "subver": "/String:0.22.5.6/",
  "inbound": false,
  "synced_blocks": 77980
}
{
  "addr": "208.62.262.244:55226",
  "subver": "/String:0.22.5.7/",
  "inbound": true,
  "synced_blocks": 77978
}
{
  "addr": "200.2.222.25:50452",
  "subver": "/String:0.22.5.7/",
  "inbound": true,
  "synced_blocks": 77980
}
{
  "addr": "220.92.79.44:50970",
  "subver": "/String:0.22.4.2/",
  "inbound": true,
  "synced_blocks": -2
}
{
  "addr": "45.22.228.69:57462",
  "subver": "/String:0.22.5.7/",
  "inbound": true,
  "synced_blocks": 77980
}
{
  "addr": "29.206.256.229:8268",
  "subver": "/String:0.22.5.7/",
  "inbound": false,
  "synced_blocks": 77980
}

另外

select(.subver | contains("0.22.5.7") | not)

用于显示subver不包含&#34; 0.22.5.7&#34;的结果。但是对于这两种情况,我都无法适应OR。

如何仅显示subver不包含的结果&#34; 0.22.5.7&#34;或.synced_blocks&lt; 77982?

1 个答案:

答案 0 :(得分:0)

这里主要的非显而易见的事情是后期修复&#34;不是&#34;:

select( ( .subver | test("(^|:)0.22.5.7($|/)") | not) or
        .synced_blocks < 77982)