我想要减少/组合以下两个数组。电子邮件应该是唯一的。
阵列1:
[
{
"EMAIL": "email1@myDomain.com",
"INUSE": "1"
},
{
"EMAIL": "email4@myDomain.com",
"INUSE": "1"
},
{
"EMAIL": "email7@myDomain.com",
"INUSE": "1"
},
{
"EMAIL": "email2@myDomain.com",
"INUSE": "3"
}
]
阵列2:
[
{
"EMAIL": "email1@myDomain.com",
"FREE": "1"
},
{
"EMAIL": "email3@myDomain.com",
"FREE": "2"
},
{
"EMAIL": "email4@myDomain.com",
"FREE": "2"
}
]
jq -s 'add'
组合该阵列。我对unique
和reduce
做了一些研究,但我无法使其发挥作用。
期望输出:
[
{
"EMAIL": "email1@myDomain.com",
"FREE": "1",
"INUSE": "1"
},
{
"EMAIL": "email4@myDomain.com",
"INUSE": "1",
"FREE": "2"
},
{
"EMAIL": "email7@myDomain.com",
"INUSE": "1"
},
{
"EMAIL": "email2@myDomain.com",
"INUSE": "3"
},
{
"EMAIL": "email3@myDomain.com",
"FREE": "2"
}
]
请注意,EMAIL值是唯一的。有人能帮忙吗?
您要查找的是group_by
,而不是unique
。在连接输入后,通过.EMAIL
对结果数组的元素进行分组,并合并每个组的成员以获得所需的结果。
jq -s 'add | group_by(.EMAIL) | map(add)'