Good day everyone!
I have a huge file:
1| something
2| something else
2| something else 2
2| something else 3
3| something else 4
3| something else 5
5| something else 6
...
28| something else 29
What I need is to split this one file in 28 different files. Like file1 containing everything that starts with 1|
, file2 with 2|
, etc.
The file is about 400GB. Is there a performant, easy way to do this?
Thanks alot!
edit:
this is what I've done and it takes ages
for line in r_file:
var.append(line)
r_file.close()
for i in range(1, 29):
w_file = open('/file' + str(i) + '.txt', 'a', encoding='utf-8')
for line in var:
if line.startswith(str(i) + '|'):
w_file.write(line)
w_file.close()```