使用jq到Concat的目录中的JSON文件.
该目录包含几十万个文件.
jq -s '.' *.json > output.json
返回文件列表太长的错误.有没有办法写这个使用一个将接收更多文件的方法?
如果jq -s . *.json > output.json产生"参数列表太长"; 你可以在zsh中使用它修复它zargs:
$ zargs *.json -- cat | jq -s . > output.json
Run Code Online (Sandbox Code Playgroud)
您可以使用@ chepner的答案中find所示进行模拟:
$ find -maxdepth 1 -name \*.json -exec cat {} + | jq -s . > output.json
Run Code Online (Sandbox Code Playgroud)
"jq中的数据表示为JSON值的流......这是一种cat友好的格式 - 您可以将两个JSON流连接在一起并获得有效的JSON流." :
$ echo '{"a":1}{"b":2}' | jq -s .
[
{
"a": 1
},
{
"b": 2
}
]
Run Code Online (Sandbox Code Playgroud)