One of the problems with your initial attempt is that your regex only processes comments that are completely single-line related. In addition, the leading and ending “. *” Will delete the text without comment.
You are better off using existing code instead of rolling around on your own.
http://sed.sourceforge.net/grabbag/scripts/strip_html_comments.sed
#! /bin/sed -f # Delete HTML comments # ie everything between # by Stewart Ravenhall < stewart.ravenhall@ukonline.co.uk > //!{ N ba } s///
(from http://sed.sourceforge.net/grabbag/scripts/ )
See this link for different ways to use perl modules to remove HTML comments (using Regexp :: Common, HTML :: Parser or File :: Comments.) I'm sure there are methods that use other utilities.
http://www.perlmonks.org/?node_id=500603
source share