import re, sys
myregex = re.compile(sys.argv[2])
i = 0
fh = open(sys.argv[1])
for line in fh:
    i += len(myregex.findall(line))
fh.close()
print(i)

This code is part of the book "Python for Bioinformatics", by Sebastian Bassi (sbassi@genesdigitales.com). Return to home page.