Sounds like something for the grep tool.
Linux in a Nutshell by Ellen Siever, Stephen Figgins, Robert Love, and Arnold Robbins, page 182, wrote:grep
grep [options] pattern [files]
Search one or more files for lines that match a regular expression pattern. Regular expressions are described in Chapter 7. Exit status is 0 if any lines match, 1 if none match, and 2 for errors. See also egrep and fgrep
Of course, that probably won't work on a Windows® box.
Start by writing down an algorithm you intend to follow. Make it simple. Very simple.