I'd like to count the number of occurrence of multiple patterns from each line in a file. so if any of patterns found from line, I'd like to increase the counter by 1 so in the end, I can come up with the total number of lines that includes the patterns that I defined. but I'm stuck to search multiple pattern in a single line but increase count by 1 if found any patterns. can anyone advise on this? and can I make single pattern that covers three patterns I defined?
def sample_output(input_file):
lines_detect_pattern = 0
lines_not_detect_pattern = 0
patterns =['HELLO\(L[0-9]\)\:\[APP*?\]',
'HELLO\(L[0-9]\)\:\[Unknown\]\[APP.*?\]',
'HELLO\(L[0-9]\)\:\[Known\]\[APP.*?\]',
]
myfile = open(input_file, 'r')
outfile = open(final_file,'a+')
for line in myfile:
for pattern in patterns:
if pattern.search(line)
outfile.write("Total number of system passed PMEM : %s \n" %pmem_pass)
outfile.write("Total number of system failed PMEM : %s \n" %pmem_fail)
outfile.close()
myfile.close()