I have a text file like this:
('1', '2')
('3', '4')
.
.
.
and I'm trying to make it look like this:
1 2
3 4
etc...
I am trying to do this with the re module in python by combining the re.sub commands as follows:
for line in file:
s = re.sub(r"\(", "", line)
s1 = re.sub(r",", "", s)
s2 = re.sub(r"'", "", s1)
s3 = re.sub(r"\)", "", s2)
output.write(s3)
output.close()
It seems to work just fine until I get to the end of my output file; then it becomes inconsistent and stops working. I think this is because of the explicit SIZE file I'm working with; 300 MB or approximately 12 million lines.
Can someone help me confirm that I just do not have enough memory? Or if it is something else? Suitable alternatives or ways around this?
source
share