Prefetch Technologies // Keeping your cache lines cozy

Formatting text for printing

I periodically need to format text data on my Linux desktop for printing, and have always gone about this in one of two ways. If I want to add margins and make the data conform to a specific page length, I use the pr utility. Here is an example that formats FILE with a #4 margin, a #72 width (the default), and a length of 60 lines:

$ pr -o 4 -l 60 FILE

If I have a text document that I want to format to 80-characters per line, I typically use fmt with the width option. The following example will force all lines to 80 characters, and will gracefully wrap lines if they exceed this limit:

$ fmt -80 FILE

If you have any other methods for formatting text, I would love to hear them.