Skip to content

Instantly share code, notes, and snippets.

@Jlaird
Created April 30, 2019 18:33
Show Gist options
  • Save Jlaird/7aea5ff8f18de7d72fc78b42832a102e to your computer and use it in GitHub Desktop.
Save Jlaird/7aea5ff8f18de7d72fc78b42832a102e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Total number of lines in file
filelines=$(wc -l < $2)
# Number of chunks in the array
split=$1
# Loop counter
counter=0
# Figures out skip based on lines and split
chunk=$(($filelines / $split))
end=$chunk
start=0
chunkList=[]
while [ $counter -lt $split ]; do
sedStart=$(($start + 1))
sedEnd="$(($end + 1))p"
# Chunk into array
chunkList[$counter]="$(sed -n $sedStart,$sedEnd < $2)"
start=$(($end + 1))
end=$(($end + $chunk + 1))
let counter++
done
echo ${chunkList[@]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment