- 論壇徽章:
- 0
|
本帖最后由 yhizyh 于 2015-11-20 23:46 編輯
今天遇到一個(gè)問題,處理幾個(gè)大文件,1個(gè)文件為2G ,1個(gè)文件大小為 4G,我看了一下里面數(shù)據(jù)條數(shù)是129115369 條,現(xiàn)在這些數(shù)據(jù)有很多都是重復(fù)的,不是逐行重復(fù),不一定那條和那條重復(fù),我要去掉重復(fù)數(shù)據(jù),可是用了set 、sort都不能正常處理這個(gè)文件,肯定不是我程序的問題,同樣內(nèi)容的文件我處理800-900M都可以,就是2個(gè)特大的處理不了。所以請(qǐng)教一下對(duì)于這種特大文件有什么辦法沒有。謝謝了
-rw-rw-r-- 1 root root 2.7G 11月 20 21:24 f10.txt
-rw-rw-r-- 1 root root 4.6G 11月 20 22:40 f11.txt
-rw-rw-r-- 1 root root 65M 11月 20 20:33 f6.txt
-rw-rw-r-- 1 root root 218M 11月 20 20:34 f7.txt
-rw-rw-r-- 1 root root 604M 11月 20 20:38 f8.txt
-rw-rw-r-- 1 root root 1.4G 11月 20 20:51 f9.txt
-rw-r----- 1 root root 838 11月 20 22:50 RemoveSimilar.py
目前就是兩個(gè)最大的文件處理不了。
通過list(set())方法處理的部分代碼- def modi_File(filename):
- sFile="out/"+filename
- oFile="out1/"+filename
- fp = file(sFile,"r")
- lines = fp.readlines()
- fp.close()
- index =0
- count =len(lines)
- while index<count:
- lines[index]=lines[index].strip("\n")
- index +=1
- flines=list(set(lines))
- fp_w=file(oFile,"w")
- count=0
- for line in flines:
- fp_w.write(str(line)+"\n")
- count +=1
- fp_w.write("數(shù)據(jù)總量:%s"%count)
- fp_w.close()
復(fù)制代碼 |
|