Bash Split Array Into Chunks

[Solved] Bash Split Array Into Chunks | Swift - Code Explorer | yomemimo.com
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

Answers related to bash split array into chunks

Code Explorer Popular Question For Swift