So really there are two operations to perform. First re-wrap the lines to the width you want, then paginate the text to the desired length, outputting one page at a time. Correct?
A couple more clarification questions here. You want to rewrap the text, but not the dashed lines separating blocks, right? Also, do the separators always separate single lines of text, or could there be more than one in each section (i.e. newlines or even blank lines). Are there any other possible formatting gotchas to worry about?
Just monkeying about for few minutes though, I came up with this for the first operation:
Code:
linewidth=78
sed 's/^_\+$/<linebreak>/' sample_text.txt | fold -sw "$linewidth" | \
sed 's/<linebreak>/__________________________________________________________________________________________/'
Formatting the bulk of the text while excluding the separators is a little challenging, so I just applied a brute-force method. I used sed to replace the separators with a substitute string, used fold to wrap the text, then converted the separator back to full length. Hey, it works.
Not to sure how to paginate it though, especially while controlling the timing of the output. You could use sed to break it up, and perhaps use a loop of some kind to control the timing of the output based on user input. I'd have to think about it a bit more.
It might be better to go about this with something like perl, which I personally don't know much about.