You cannot do this reliably with grep only. You need to parse HTML using an HTML parser.
What if the HTML code has something like:
You will get a false hit on this code with comments.
Consider using xmlgrep from the XML::Grep Perl module, as described here: Retrieve html file header using grep
Andy lester
source share