Nine Years of Service
Posts: 3,085
Threads: 132
RE: Does such a tool exist? 06-25-2019, 10:46 PM
#3
Ohh so you want to input a number and have a program split a list into equal groups. I'm sure that would be relatively easy to make, but I can't right now.
(This post was last modified: 06-25-2019, 10:46 PM by Drako.)
•
Seven Years of Service
Posts: 62
Threads: 6
RE: Does such a tool exist? 06-26-2019, 12:04 PM
#4
That would be easy to do in python. Just had a quick look on stack overflow and edited it so it should split into three parts.
def file_len(fname):
with open(fname) as f:
for i, l in enumerate(f):
pass
return i + 1
#change input.txt to your file name
line_num = file_len(input.txt)
splitLen = line_num/3 # 20 lines per file
outputBase = 'output' # output.1.txt, output.2.txt, etc.
input = open('input.txt', 'r').read().split('\n')
at = 1
for lines in range(0, len(input), splitLen):
# First, get the list slice
outputData = input[lines:lines+splitLen]
# Now open the output file, join the new slice with newlines
# and write it out. Then close the file.
output = open(outputBase + str(at) + '.txt', 'w')
output.write('\n'.join(outputData))
output.close()
# Increment the counter
at += 1
Not tested it but it should work.
•
Ten Years of Service
Posts: 1,897
Threads: 94
RE: Does such a tool exist? 06-26-2019, 01:51 PM
#5
I had coded this a year ago but I lost it, it is very helpfull with threading.
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
![[Image: p_237m2jx1.png]](http://c.top4top.net/p_237m2jx1.png)
Click for Free VPN
•