Hi,
I have two files. One is a csv and contains the search strings (one per line) and the other is a huge file which contains the search term at the start of each line but has extra information after which I would like to extract.
The search terms file is called 'search.csv' and looks like this:
3ksr
3ky8
2g5w
2gou
The file containing the other info is called 'CSA.txt' and looks like this:
3ksr,INFO.....
3ky8,INFO.....
2g5w,INFO.....
2gou,INFO.....
However, it is a very big file (over 8mb) and each search term has more than one occurence but the information is different for every occurence. I have some sample code:
import fileinput
import csv
csa = fileinput.input("CSA.dat", inplace=1)
pdb = csv.reader(open("search.csv"))
outfile = csv.writer(open("outfile.csv"), dielect = 'excel', delimiter = '\t')
for id in pdb:
for line in csa:
if id in str(line):
outfile.writerow([id, line])
csa.close()
However, this code doesnt work and seems to delete CSA.dat every time I try and run it (its backed up in an archive), or it says 'Text file busy'. Please help! Thanks in advance!