Json
jq - 選擇以字元串開頭的屬性
輸入json:
[ { "id": "89", "hostname": "abcd" }, { "id": "89", "hostname": "babcd" } ]
如何修改以下過濾器以僅輸出以“abcd”開頭的主機名?
$ jq -r '.[]|select(.hostname | contains("abcd"))' jjjj { "id": "89", "hostname": "abcd" } { "id": "89", "hostname": "babcd" } $ jq -r '.[]|select(.hostname | contains("^abcd"))' jjjj $
解決方案:
jq -r '.[]|select(.hostname | startswith("abcd"))' jjjj