5
cat 2.txt | ./jq '{(.id): .custom}'

上記のコマンド出力

{
  "1": {
    "results": "Success"
  }
}
{
  "2": {

    "input method": "touch",
    "from": "Prescription Center",

  }
}
{
  "3": {

    "entry point": "|All"
  }

}

期待される出力:

各オブジェクトを1行に印刷/保存したい。

cat 2.txt | ./jq '{(.id): .custom}'

{ "1": {  "results": "Success" }  }
{ "2": {  "input method": "touch",  "from": "Prescription Center"  }  }
{ "3": {  "entry point": "|All" } }

シェルスクリプトで可能ですか?

4

1 に答える 1

15

jqマニュアルによると

  • --compact-output/ -c:

    デフォルトでは、jq は JSON 出力をプリティプリントします。このオプションを使用すると、代わりに各 JSON オブジェクトを 1 行に配置することで、よりコンパクトな出力が得られます。

したがって、次のように動作するはずです。

cat 2.txt | ./jq -c '{(.id): .custom}'
于 2014-08-24T06:08:32.503 に答える