I have a folder containing multiple files. I want to count the number of files that contains matching text say "Pathology" or a pattern say "ORC|||||xxxxxxxx||||||" inside it from those files present inside the folder. I have tried following scripts :
import re, os
import glob
list_of_files = glob.glob('./*.hl7')
for fileName in list_of_files:
fin = open( fileName, "r" )
count = 0
for line in fin:
if re.match("Pathology", line):
count +=1
fin.close()
print count
This gives me result as 0. I am using python 2.6.6. and have no options of upgrading my python. Please suggest a way to do this.
grep -l "Pathology\|ORC" *.hl7??if 'Pathology' in line:..count +=1? Also why every time you makecount=0for each file? see stackoverflow.com/questions/11162711/…