English 中文(简体)
• 任意挑选人数的JSON文档,其中jq
原标题:Combine an arbitrary number of JSON files with jq
  • 时间:2024-03-16 23:07:57
  •  标签:
  • bash
  • jq

我可以使用jq将2个json档案合并起来,从而:

jq -s  .[0] * .[1]  file1.json file2.json >merged.json

我可以把黑森档案中的任意数目合并起来,使用 lo和第二代及随后的斜体,把以前的作业产出作为投入之一。 加上工艺替代,可以通过管道进行:

jq -s  .[0] * .[1]  file1.json file2.json | 
   jq -s  .[0] * .[1]  <(cat) file3.json | 
   jq -s  .[0] * .[1]  <(cat) file4.json ...

但是,我怎么能够把任意数目的档案合并起来,而不撰写中间版本?

(我设想,通过一个核查和核查小组,我会处理大量文件/档案——我对此没有关切。)

问题回答

Be aware that * potentially does more than you might think. (See https://jqlang.github.io/jq/manual/v1.7/#multiplication-division-modulo for details.)

物体上的“+”操作者不太复杂,因此机会是,像以下这样的企业将满足你的需要:

jq -n  [inputs] | add  file*.json

你们可以单独呼吁放弃:

jq -n  reduce inputs as $i({};. * $i)  file{1..4}.json




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签