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脚本中使用吗?
答案 0 :(得分:11)
--compact-output
/-c
:默认情况下,jq漂亮打印JSON输出。使用此选项将导致更紧凑的输出,而不是将每个JSON对象放在一行上。
因此以下内容应该有效:
cat 2.txt | ./jq -c '{(.id): .custom}'