I got a text file file.txt
(12 MBs) containing:
something1
something2
something3
something4
(...)
Is there any way to split
Using bash:
readarray -t LINES < file.txt
COUNT=${#LINES[@]}
for I in "${!LINES[@]}"; do
INDEX=$(( (I * 12 - 1) / COUNT + 1 ))
echo "${LINES[I]}" >> "file${INDEX}.txt"
done
Using awk:
awk '{
a[NR] = $0
}
END {
for (i = 1; i in a; ++i) {
x = (i * 12 - 1) / NR + 1
sub(/\..*$/, "", x)
print a[i] > "file" x ".txt"
}
}' file.txt
Unlike split
this one makes sure that number of lines are most even.