伙計,長期看這個板并學習了很多,但現在遇到了小問題。我正在使用讀取 json 的 Linux shell 腳本(這里沒問題)。我想做的是從具有特定型別的條目中獲取價值。
通過用 just 決議 json jq -r '.',我得到
{
"records": [
{
"id": 01,
"type": "SOA",
"name": "@",
"data": "1800",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
},
{
"id": 02,
"type": "A",
"name": "@",
"data": "test.com",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
}
],
"links": {},
"meta": {
"total": 2
}
}
然后,我使用 "jq -r '.records' "并得到:
[
{
"id": 01,
"type": "SOA",
"name": "@",
"data": "1800",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
},
{
"id": 02,
"type": "A",
"name": "@",
"data": "test.com",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
}
]
我需要做的是獲取 A 型別的資料值。目前,我們有 SOA 和 A 型別,但我只需要從 A 獲取資料。
我可以使用 dummy 方式,"jq -r '.records[1].data'"它給了我正確的回應test.com,但我想要一種更動態的方式來搜索特定型別(在本例中為“A”),然后給出資料值。
多謝你們!
uj5u.com熱心網友回復:
該領域是被稱為domain_records還是只是records?
用于select匹配您的條件
jq -r '.records[] | select(.type == "A").data'
test.com
演示
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/438187.html
上一篇:獲取資料時是否有某種通配符?
下一篇:SQL以特定格式生成JSON
