A couple of thoughts:

The cutting up of input stream as you describe can be much done much easier with sed, for instance, instead of

query-students | sort | unhead '^D' | untail '^G'
query-students | sort | sed '/^D/,/^G/p; d'
Also, neither head nor tail modify files they operate on. I understand, you were probably solving a specific problem, but this script can be generalized even more.

In reply to Re: unhead and untail by dmitri
in thread unhead and untail by halley

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":