输入 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
$
答案1
解决方案:
jq -r '.[]|select(.hostname | startswith("abcd"))' jjjj