in reply to counting string in a text file

A most-engineered solution would use an HTML parser to create an XML tree, and would use XPath expressions to pluck what you needed out of that tree.