【发布时间】:2023-02-16 22:26:01
【问题描述】:
我的消息生成器输出
$ ./messages.sh
{"a":"v1"}
{"b":"v2"}
{"c":"v3"}
...
所需输出
$ ./messages.sh | jq xxxxxx
[{"a":"v1"},{"b":"v2"}]
[{"c":"v3"},{"d":"v4"}]
...
【问题讨论】:
我的消息生成器输出
$ ./messages.sh
{"a":"v1"}
{"b":"v2"}
{"c":"v3"}
...
所需输出
$ ./messages.sh | jq xxxxxx
[{"a":"v1"},{"b":"v2"}]
[{"c":"v3"},{"d":"v4"}]
...
【问题讨论】:
使用.获取第一项,使用input获取第二项。将两者都包装到数组括号中,并提供 -c 选项以实现紧凑输出。
./messages.sh | jq -c '[., input]'
[{"a":"v1"},{"b":"v2"}]
[{"c":"v3"},{"d":"v4"}]
【讨论】:
使用 slurp 和 _nwise(2) 分块成 2 的部分:
jq --slurp --compact-output '_nwise(2)' ii
[{"a":"v1"},{"b":"v2"}]
[{"c":"v3"},{"d":"v4"}]
【讨论】: