Question : bash split array into chunks
Answered by : steamboatid
#!/bin/bash
array=(aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm)
g=4
for((i=0; i < ${#array[@]}; i+=g))
do part=( "${array[@]:i:g}" ) echo "Elements in this group: ${part[*]}"
done
Source : https://stackoverflow.com/questions/23747612/how-do-you-break-an-array-in-groups-of-n | Last Update : Fri, 05 Nov 21