在 jq 命令的输出中追加字符串和特殊字符
Append string and special character in the output of jq command
我有一个 json 文件 GroupList.json:
{
"results": [
{
"type": "known",
"username": "USERID1",
"displayName": "DISPLAYNAME1",
"_links": {
"self": "https://confluence.com/rest/api/user?key=123"
},
"_expandable": {
"status": ""
}
},
{
"type": "known",
"username": "USERID2",
"displayName": "DISPLAYNAME2",
"_links": {
"self": "https://confluence.com/rest/api/user?key=1234"
},
"_expandable": {
"status": ""
}
}
],
"start": 0,
"limit": 50000,
"size": 2,
"_links": {
"self": "https://confluence.com/rest/api/group/GROUPNAME/member",
"base": "https://confluence.com"
}
}
我正在使用以下命令获取用户名:
jq -r '.results |地图(.用户名)|加入(",")' GroupList.json > UserNameList.txt
UserNameList.txt 中的输出是:
USERID1,USERID2
我想将输出修改为:
SPACEKEY : 群组名称 : USERID1,USERID2
SPACEKEY 和 GROUPNAME 是 2 个变量,其值在每次迭代中都会发生变化。
对于您的文件,以下调用会产生如下所示的输出:
jq -r --arg prefix "SPACEKEY : GROUPNAME : " '
$prefix + (.results | map(.username) | join(","))
' GroupList.json
输出
SPACEKEY : GROUPNAME : USERID1,USERID2
我有一个 json 文件 GroupList.json:
{
"results": [
{
"type": "known",
"username": "USERID1",
"displayName": "DISPLAYNAME1",
"_links": {
"self": "https://confluence.com/rest/api/user?key=123"
},
"_expandable": {
"status": ""
}
},
{
"type": "known",
"username": "USERID2",
"displayName": "DISPLAYNAME2",
"_links": {
"self": "https://confluence.com/rest/api/user?key=1234"
},
"_expandable": {
"status": ""
}
}
],
"start": 0,
"limit": 50000,
"size": 2,
"_links": {
"self": "https://confluence.com/rest/api/group/GROUPNAME/member",
"base": "https://confluence.com"
}
}
我正在使用以下命令获取用户名: jq -r '.results |地图(.用户名)|加入(",")' GroupList.json > UserNameList.txt
UserNameList.txt 中的输出是: USERID1,USERID2
我想将输出修改为:
SPACEKEY : 群组名称 : USERID1,USERID2
SPACEKEY 和 GROUPNAME 是 2 个变量,其值在每次迭代中都会发生变化。
对于您的文件,以下调用会产生如下所示的输出:
jq -r --arg prefix "SPACEKEY : GROUPNAME : " '
$prefix + (.results | map(.username) | join(","))
' GroupList.json
输出
SPACEKEY : GROUPNAME : USERID1,USERID2