Split a table into N output files


I have a table that I would like to split into a specified number of output CSV files - such that each CSV file has roughly equal number of lines and none are more than a certain number of lines long. The source table itself will be of variable length, hence the number of files to write out can be variable as well.

I’ve solved this problem before when I knew that it was appropriate to write out 4 files; I used “Random Number Assigner” to help split the lines into the files. But going forward I won’t know how many files to write out so I’d like to use a loop (or loop-like structure) to accomplish this.

thank you


Try a chunk loop start and set the chunk size



I modified a workflow I had. You define a size of your resulting files and the workflow would split all data into equal chunks and the last chunk would hold the rest.

May be there is a more elegant way, and you might modify the workflow so as to give the no of chunks you want and then split the data accordingly.

kn_example_split_files_equal.knwf (76.6 KB)