我正在尝试从同时具有这两种特性的JSON中输出displayName
"source": "0.0.0.0/0" and
tcpOptions": "destinationPortRange": "min": 80结果应仅显示
rule-1例如: JSON
[
{
"displayName": "rule-1",
"secrule": [
{
"source": "0.0.0.0/0",
"tcpOptions": {
"destinationPortRange": {
"min": 80,
"max": 80
}
}
},
{
"source": "0.0.0.0/0",
"tcpOptions": {
"destinationPortRange": {
"min": 443,
"max": 443
}
}
}
]
},
{
"displayName": "rule-2",
"secrule": [
{
"source": "0.0.0.0/0",
"tcpOptions": {
"destinationPortRange": {
"min": 443,
"max": 443
}
}
},
{
"source": "20.0.0.0/0",
"tcpOptions": {
"destinationPortRange": {
"min": 80,
"max": 80
}
}
}
]
}
]我试过了
jq -r '.[] | select(.secrule[].source == "0.0.0.0/0" and .secrule[].tcpOptions.destinationPortRange.min == 80) | .displayName' JSON | sort -u但它同时显示两个规则(这是不正确的)
rule-1
rule-2发布于 2019-09-06 02:40:39
您扩展了.secrule两次,因此它的每个元素组合都会得到检查。请改用any:
.[] | select(any(.secrule[]; .source=="0.0.0.0/0" and .tcpOptions.destinationPortRange.min==80)).displayNamehttps://stackoverflow.com/questions/57811213
复制相似问题