i have a list/array of per line quoted strings in a list.json file. this file is dynamically generated and fluctuates from 1 to inf in size. currently 127 elements. i need to process every line no matter if its 1 or inf.
[
"p1",
"p2",
...,
"p127"
]
these params need to be tacked onto a command flag within an array eg. command --params=["p1","p2","...","p20"]
it can take up to a max of 20 per command.
currently im just going through generating one command for every param in my list.json, using a simple for loop. eg below
lines="$(cat list.json)"
for l in ${lines} ;
do
command --params=[${l}]
done
eg. currently generates and runs 127 loops:
command --params=["p1"]
command --params=["p2"]
...
command --params=["p127"]
etc. and i save the outputs.
this is the obvs basic, and very inefficient & slow method. so ideally i want to reduce my total number of commands so its using max params eg. 20 in each loop eg.
1st loop = command --params=["p1","p2",..."p20"]
2nd loop = command --params=["p21","p22",..."p40"]
etc.
this has two problems i need to address.
i dunno how to do that in a for loop...looking at a bunch of examples of for loops for specifying some logic for sequence & increments which is obvs enough, but im really not sure what are you supposed to do where you want it to batch multiple lines per loop, eg like a range of 20 lines at a time? seems simple enough to me, but havent had to do it before.
potentially dealing with any comma separation situation from the array of params. eg. splitting the elements 20 at a time, into their own not malformed json array ie. without trailing commas etc.