【发布时间】:2018-07-01 22:50:35
【问题描述】:
所以我有一个这样的数据源:
{
"things": [
{
"thing_name": "Bestco",
"thing_id": 1
},
{
"thing_name": "GreatCo",
"thing_id": 2
},
{
"thing_name": "DressCo",
"thing_id": 3
}
]
}
我想得到这样的输出:
$ echo '{"things":[{"thing_name":"Bestco","thing_id":1},{"thing_name":"GreatCo","thing_id":2},{"thing_name":"DressCo","thing_id":3}]}' |
jq -r '.things | map(.thing_name, .thing_id, "\n") | @csv' |
sed -e 's/,"$//g' -e 's/^",//g' -e 's/^"$//g'
"Bestco",1
"GreatCo",2
"DressCo",3
$
使用假参数似乎是一种 hack,然后需要通过 sed 清理才能工作。我如何只用 jq 做到这一点。
【问题讨论】: