有人能帮我从下面的json输出中根据起始名称过滤多个值吗。我可以过滤相同类型属性的值,但不能过滤同一查询中的其他值。
{
"app1.btch_src": {
"eventrate": 0,
"end2end": {
"data": [
{
"at": 16054343444,
"source": "app1.btch_src",
"latency": 0.05,
"target": "app1.btch_tgt"
}
]
}
},
"app1.btch1_src": {
"eventrate": 0,
"end2end": {
"data": [
{
"at": 16054343445,
"source": "app1.btch1_src",
"latency": 200.5,
"target": "app1.btch1_tgt"
}
]
}
},
"app2.btch_src": {
"eventrate": 0,
"end2end": {
"data": [
{
"at": 16054341234,
"source": "app2.btch_src",
"latency": 50.4,
"target": "app2.btch_tgt"
}
]
}
},
"app3.btch_src": {
"eventrate": 0,
"end2end": {
"data": [
{
"at": 16054343444,
"source": "app3.btch_src",
"latency": 10,
"target": "app3.btch_tgt"
}
]
}
}
}
我编写了如下查询,因为如果延迟超过10秒,我想同时检索app1.*
和app2.*
对象值。当我在下面选择一个属性并且它正在工作时。
jq -r '.[] |.end2end.data[0] | select(.latency>10) |select(.source |startswith("app1")' all_info.json
我现在需要知道,如果满足上述条件,我如何检索app2
和app1
的值。
您可以简单地or
条件,例如使用您的方法:
.[]
| .end2end.data[0]
| select(.latency>10)
| select(.source | (startswith("app1") or startswith("app2")) )
或者可以使用正则表达式,例如
select( .source | test("^app[12]") )
或者
select( .source | test("^app[12][.]") )