|
Hi Everybody,
I have a text file that can have any number of lines.
I want to split the file into 6 files as evenly as possible (by lines)
I can do a simple
number=`cat file.txt.txt | wc -l`
number=`expr $number / 6 `
split -l $number file.txt
However this does not give a fair allocation of lines and does not always give 6 files.
Examples:
for a file with 22 lines I would like 4 files of 4 lines and 2 files of 3 lines, 4 4 4 4 3 3
for 23 lines I would like 5 files of 4 lines and 1 file of 3 lines, 4 4 4 4 4 3
for 24 lines I would like 6 files of 4 lines, 4 4 4 4 4 4
for 25 lines I would like 5 files of 4 lines and 1 of 5 lines, 4 4 4 4 4 5
for 26 lines I would like 4 files of 4 lines and 2 files of 5 lines, 4 4 4 4 5 5
for 27 lines I would like 3 files of 4 lines and 3 files of 5 lines, 4 4 4 5 5 5
and so on.
The numbers don't need to be in any particular order, for the last example it could be 5 5 5 4 4 4 or 4 5 5 4 4 5
Regards
Robert Stanford
|