我正在使用gcloud describe命令來獲取有關實例的元數據信息。用jq過濾json響應以獲取實例的名稱的最佳方式是什麼 - 如果它包含「kafka」作爲鍵。如何用jq過濾唯一值?
.name +「」+ .metadata.items [] ?. key | select(contains(「kafka」))'
基本上如果項目包含kafka打印名稱。這只是json文件的一小段摘錄。
"metadata": {
"fingerprint": "xxxxx=",
"items": [
{
"key": "kafka",
"value": "xxx="
},
{
"key": "some_key",
"value": "vars"
}
],
"kind": "compute#metadata"
},
"name": "instance-name",
"networkInterfaces": [
{
"accessConfigs": [
{
"kind": "compute#accessConfig",
"name": "External NAT",
"natIP": "ip",
"type": "ONE_TO_ONE_NAT"
}
],
"kind": "compute#networkInterface",
"name": "",
"network": xxxxx
}
],
JQ具有['unique'](https://stedolan.github.io/jq/manual/#unique ,unique_by \(path_exp \))函數。 –
給定片段不包含「名稱」,實際上不是有效的JSON。請提供一個最小完整的可驗證示例(請參閱http://stackoverflow.com/help/mcve)。 – peak