The sequence of x followed by
G is a way to find a matching line -- in this
case, </body> -- and insert the contents
of the hold space before the matched line. In other words,
it's like an i command that
inserts the hold space at the current line.
The script could do more cleanup and formatting. For instance, it
could make the saved headings into a list with
<ul> and <li>. But
this example is mostly about the hold space.
Here's the result of running the script on the
sample file:
% sed -f sedscr report.html
...
<body>
<h1>Introduction</h1>
The blah blah blah
<h1>Background of the Project</h1>
...
<h2>The First Year</h2>
...
<h2>The Second Year</h2>
...
<strong>Summary:</strong>
Introduction
Background of the Project
The First Year
The Second Year
</body>