I have a file as below with n number of rows, I want to total it's sum(based on 3rd column) and distribute rows accordingly in 3 different files(based on sum of each)
For example- if we sum all the 3rd column values it's total is coming as 516 and if we divide it by 3 it is 172.
So i want to add a rows to a file so it doesn't exceed 172 mark, same with the 2nd file and rest all rows should move to the third file.
Input file
a aa 10
b ab 15
c ac 17
a dy 30
y ae 12
a dl 34
a fk 45
l ah 56
o aj 76
l ai 12
q al 09
d pl 34
e ik 30
f ll 10
g dl 15
h fr 17
i dd 23
j we 27
k rt 12
l yt 13
m tt 19
expected output
file1(total -163)
a aa 10
b ab 15
c ac 17
a dy 30
y ae 12
a dl 34
a fk 45
file2 (total-153)
l ah 56
o aj 76
l ai 12
q al 9
file3 (total - 200)
d pl 34
e ik 30
f ll 10
g dl 15
h fr 17
i dd 23
j we 27
k rt 12
l yt 13
m tt 19