cat 2.txt | ./jq '{(.id): .custom}'
上述命令输出
{
"1": {
"results": "Success"
}
}
{
"2": {
"input method": "touch",
"from": "Prescription Center",
}
}
{
"3": {
"entry point": "|All"
}
}
预期产出:
我想在一行中打印/保存每个对象。
cat 2.txt | ./jq '{(.id): .custom}'
{ "1": { "results": "Success" } }
{ "2": { "input method": "touch", "from": "Prescription Center" } }
{ "3": { "entry point": "|All" } }
这在shell脚本中是可能的吗?
发布于 2014-08-24 06:08:32
--compact-output
/ -c
:
默认情况下,jq漂亮地打印JSON输出。使用此选项将导致更紧凑的输出,方法是将每个JSON对象放在一行上。因此,下列各项应能发挥作用:
cat 2.txt | ./jq -c '{(.id): .custom}'
https://stackoverflow.com/questions/25467344
复制相似问题