Posts

Showing posts from October, 2016

Pick Matching lines with list of keywords

#Simple code to find the occurrence of list of search terms in single line in a huge file. Search_terms=['A','B','C','D']withopen('BigFile.txt','r')asinfile:entries=infile.read()each_line=entries.splitlines()new_list=[]forix,rowinenumerate(each_line):element=row.split("\t")ifset(Search_terms)==set(element):#Use <= if you want no strict optionnew_list.append(element)printix+1#List the matching line number !thefile=open('Output.txt','w')foriteminnew_list:print>>thefile,item