Replace in large text file ?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Jun 5 04:06:41 EDT 2010


On Sat, 05 Jun 2010 00:53:23 -0700, Steve wrote:

> I am new to Python and am wanting  to replace characters in a very large
> text file.....6 GB
> In plain language what I wish to do is:
> 
> Remove all comma's
> Replace all @ with comma's
> Save as a new file.


input_file = open("some_huge_file.txt", "r")
output_file = open("newfilename.txt", "w")
for line in input_file:
    line = line.replace(",", "")
    line = line.replace("@", ",")
    output_file.write(line)
output_file.close()
input_file.close()


-- 
Steve



More information about the Python-list mailing list