So, i already know how to successfully read every N lines in parallel, and run a command on each of those lines:
while read -r i && read -r a && read -r b && read -r c && read -r d && read -r e && read -r f && read -r g && read -r h && read -r j && read -r k && read -r l && read -r m && read -r n && read -r o && read -r p && read -r q && read -r r && read -r s && read -r t && read -r u && read -r v && read -r w && read -r x && read -r z && read -r aa && read -r bb && read -r cc && read -r dd && read -r ee && read -r ff && read -r gg && read -r hh && read -r ii && read -r jj; do
dosomething "$i" &
dosomething "$a" &
dosomething "$b" &
dosomething "$c" &
dosomething "$d" &
dosomething "$e" &
dosomething "$f" &
dosomething "$g" &
dosomething "$h" &
dosomething "$j" &
dosomething "$k" &
dosomething "$l" &
dosomething "$m" &
dosomething "$n" &
dosomething "$o" &
dosomething "$p" &
dosomething "$q" &
dosomething "$r" &
dosomething "$s" &
dosomething "$t" &
dosomething "$u" &
dosomething "$v" &
dosomething "$w" &
dosomething "$x" &
dosomething "$z" &
dosomething "$aa" &
dosomething "$bb" &
dosomething "$cc" &
dosomething "$dd" &
dosomething "$ee" &
dosomething "$ff" &
dosomething "$gg" &
dosomething "$hh" &
dosomething "$ii" &
dosomething "$jj" &
wait
done < somefile
Where dosomething is just an example function/application that do something with the specific line (which is represented by the variable next to it).
Essentially this work fine. Just wanted to make this work/look better by using arrays instead, but not sure how to format this so it use arrays...
Where it would generate variable names (only alpha, no number as that might create problem with the usual numbered variable, such as $1 etc) for N amount of job.
To prevent confusion: each read in the script above does "one line" each, so each read = one line. Meaning each iteration there are reading one line X amount of read. The wait at the end of each iteration wait for all jobs to finish.
Example:
- This answer does a similar thing that I'm doing, except it read from two file, two lines (one for each) at the same time. Mine does way more.
PS: I'm aware i could do something better using parallel, xargs or something else, but prefer to only use bash/POSIX if possible.
Any input appreciated.
readyou need? Why not onereadper iteration and awaitafter the loop?read? You can still execute your commands in the background (what you call "in parallel")