Sinisterly
Does such a tool exist? - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: General (https://sinister.ly/Forum-General)
+--- Forum: The Lounge (https://sinister.ly/Forum-The-Lounge)
+--- Thread: Does such a tool exist? (/Thread-Does-such-a-tool-exist)



Does such a tool exist? - Biglad465 - 06-25-2019

Been looking everywhere and can't find it. Hoping for a tool which will split a text document into 3 equal lists in the following way :

Original List :
Code:
a b c d e f

Say I enter the number 3 it would output :

Splitlists :

1 - ad
2 - be
3 - cf

That might be a bit confusing , let me know if you need more clarification?


RE: Does such a tool exist? - Tracefl0w - 06-25-2019

I believe this is the "tool" you're looking for, let me know if that's what you meant.


RE: Does such a tool exist? - Drako - 06-25-2019

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.


RE: Does such a tool exist? - Sartux - 06-26-2019

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.


RE: Does such a tool exist? - Mr.Kurd - 06-26-2019

I had coded this a year ago but I lost it, it is very helpfull with threading.