我的消息生成器输出
$ ./messages.sh
{"a":"v1"}
{"b":"v2"}
{"c":"v3"}
...
所需yields
$ ./messages.sh | jq xxxxxx
[{"a":"v1"},{"b":"v2"}]
[{"c":"v3"},{"d":"v4"}]
...
我的消息生成器输出
$ ./messages.sh
{"a":"v1"}
{"b":"v2"}
{"c":"v3"}
...
所需yields
$ ./messages.sh | jq xxxxxx
[{"a":"v1"},{"b":"v2"}]
[{"c":"v3"},{"d":"v4"}]
...
第一项用.
表示,第二项用input
表示.将它们都包装到数组括号中,并提供-c
选项以实现紧凑输出.JQ将一个接一个地处理整个输入(或两个接两个).
./messages.sh | jq -c '[., input]'
[{"a":"v1"},{"b":"v2"}]
[{"c":"v3"},{"d":"v4"}]