in reply to counting string in a text file

This is homework? (you would never have <td> tags in isolation like this in a real HTML file since they are part of a larger table definition). A few hints to get you back on track: