import re from numpy import * def getStr(file_path,file_path1): fp = open(file_path, 'r') op = open(file_path1,'w') for eachline in fp.readlines(): lines = re.split(" | | ",eachline) print(lines[2:10]) newlines=lines[2:10] i = 0 for s in newlines: i=i+1 if i<8: print(s) op.write(s+',') elif i==8: op.write(s+' ') continue else: break fp.close() op.close() if __name__ == '__main__': for i in range(483): getStr(str(i)+'.txt','result/'+str(i)+'.txt')