If I want to iterate through a text file line-by-line, here is how I do it:
for curr_line in open('my_file.txt', 'r').readlines()
print '|' + curr_line + '|'
If I want to iterate through a text based on semi-colon separators, here is how I do it:
for curr_line in open('my_file.txt', 'r').read().split(';')
print '|' + curr_line + '|'
If I want to iterate through a very large text file line-by-line, here is how I do it:
for curr_line in open('my_file.txt', 'r').xreadlines()
print '|' + curr_line + '|'
But how can I iterate through a very large text file based on semi-colon separators? It is 7+ gigabytes so I cannot read the whole thing into memory.
Below is the sample input file my_file.txt
:
AAAA;BBBBB
BB;CCC;
DDDDD
D
D;
EEEE;F
Here is the output I want to see based on the snippets above:
|AAAA|
|BBBBB
BB|
|CCC|
|DDDDD
D
D|
|EEEE|
|F|