输入json:
[
{
"name": "cust1",
"grp": [
{
"id": "46",
"name": "BA2"
},
{
"id": "36",
"name": "GA1"
},
{
"id": "47",
"name": "NA1"
},
{
"id": "37",
"name": "TR3"
},
{
"id": "38",
"name": "TS1"
}
]
}
]
如何在@tsv 输出中获取用空格分隔的 .grp[] 名称?
$ jq -r '.[]|[.name, (.grp//[{"name":"-"}]|.[]|" ",.name)]|@tsv' test_inp
cust1 BA2 GA1 NA1 TR3 TS1
上述样本的预期输出:
cust[TAB]BA2[SPACE]GA1[SPACE]NA1[SPACE]TR3[SPACE]TS1
jq
方法:输出: