import glob import os #Change Directory According to your Need os.chdir("/home/cdac/Downloads") filename_arr={} i=0 for files in glob.glob("*.txt"): filename_arr[i] = files i= i+1 print "Number files available for modifying" print i c=0 for key,value in filename_arr.items(): #Give path where you want to store your file e=open("Madhu/"+filename_arr[c],"w") print "name of opened file for writing" print filename_arr[c]; f=open(value,"r") # j=0 while True: l=f.readline() l1=len(l) if l1==0: break # if j==1: # print l for m,var in enumerate(l): if var=="[": l2=l[m-25:m+28] e.write(l2) e.write("\n") # print len(l2) # break # j=j+1 # e.write(l) e.close() f.close() c=c+1 print c # print j