【发布时间】:2018-12-13 19:38:19
【问题描述】:
json:
[
{
"account": "1",
"cost": [
{
"usage":"low",
"totalcost": "2.01"
}
]
},
{
"account": "2",
"cost": [
{
"usage":"low",
"totalcost": "2.25"
}
]
},
{
"account": "1",
"cost": [
{
"usage":"low",
"totalcost": "15"
}
]
},
{
"anotheraccount": "a",
"cost": [
{
"usage":"low",
"totalcost": "2"
}
]
}
]
预期结果:
account cost
1 17.01
2 2.25
anotheraccount cost
a 2
我能够提取数据,但不知道如何聚合它。
jq '.[] | {account,cost : .cost[].totalcost}'
有没有办法在使用 jq 时做到这一点,所以我可以得到所有类型的帐户和与之相关的费用?
【问题讨论】: