I wish I can grab the first html comment in a file using sed.Using '/<!--/,/-->/ and having more than one comment block it will match all the content between the first and the last comment block too!Any advice?Here a sample:<!-- First comment block-->Content<!--Second comment block-->The expected output should be:<!-- First comment block-->It should work with single line comments too.<!-- First comment block -->
sed edit text block: not greedy match
sed
You would do something along the lines of:sed '/<!--/,$!d;/-->/q'The first command deletes all lines but from the first matching <!-- onwards. And among those that haven't been deleted by the first command, we search for the closing tag and quit (after having printed that line as well).With perl, to strip the comment tags:perl -ln0777 -e 'print $1 if /<!--\s*(.*?)\s*-->/'