输入json:
[
{
"id": "1e9b2215-9efd-67cc-9113-2b21c74f09d3",
"login": "u0154",
"name": "Roman ABC",
"role": "User",
"groups": [
{
"id": "1e99833f-9876-65d0-9d24-237228b9d9e0",
"name": "AGE"
}
],
"disabled": false,
"lLoginTime": 1567158950468,
"lLoginFrom": "192.168.100.11"
},
{
"id": "1e9b2215-9c2b-64f4-a0f1-47abdab7ae5f",
"login": "u0155",
"name": "Tomas CDE",
"role": "User",
"groups": [
{
"id": "1e8dc82a-596f-623c-8bc5-100000000000",
"name": "ZZZ"
},
{
"id": "1e99234f-9876-65d0-9d24-534528b9d9e0",
"name": "NTE"
}
],
"disabled": false,
"lLoginTime": 1566302653093,
"lLoginFrom": "192.168.100.16"
}
]
我需要打印制表符分隔的 .id、.login 和由 | 分隔的所有用户组 (管道)或逗号
我现在拥有的:
$ jq -r '.[]|[.id, .login, ([.groups[].name]|@tsv)]|@tsv' test.json
1e9b2215-9efd-67cc-9113-2b21c74f09d3 u0154 AGE
1e9b2215-9c2b-64f4-a0f1-47abdab7ae5f u0155 ZZZ\tNTE
我需要修改过滤器,以便最后一列上的组用空格分隔或|
代替当前\t
只需使用
join()
而不是@tsv
: