0
我想通過通過標籤[]選擇這JSON outputJQ過濾器包括unfound選擇
標記過濾,如果存在鍵顯示所選擇的值。
我的JQ過濾器看起來是這樣的:
jq -r ".Reservations[]
| [.OwnerId,
.Instances[].InstanceId,
.Instances[].Placement.AvailabilityZone,
(.Instances[].Tags[]?|select(.Key==OtherTag)|.Value),
(.Instances[].Tags[]?|select(.Key==Name)|.Value) ]
| @csv"
輸出看起來像這樣
"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,webserver2"
我想它包括毫無根據選擇的標籤,並在CSV填充它作爲空場 象下面這樣:
"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,,webserver2"
我應該在JQ如何實現呢?有人能給我一個例子嗎?
所以我在這裏做了一點進步的解決方案。通過使用地圖和選擇。 '。保留[] | [.OwnerId,.Instances []。InstanceId,.Instances []。Placement.AvailabilityZone,(.Instances []。Tags | map(if(select(.Key ==「Name」))then .Value else「」end )),(.Instances []。Tags | map(if(select(.Key ==「OtherTag」)).Value else「」end))]'但是我現在結果爲空數組[ 。無論如何將空數組轉換爲空值?基本上壓縮該數組的所有值到一個字符串?希望這是有道理的 – hutanrimba