Formatting Text Files for Viewing and Printing

The commands illustrated in this section offer ways to take plain text files and tidy them up or present them differently for display or printing.

The pr command takes a text file and splits it into pages of text separated by a number of new-lines with a header on each page. Optionally, it can add a form feed character between the pages for sending the output directly to a printer. For example, using the command with no options:

[email protected]:~ > pr README.txt will output pages with a header on each looking like this:

2004-08-10 12:26 INDEX Page 1


The fold command reformats a text file by breaking long lines. By default, the lines will be set to a maximum width of 80 characters. You can set the width of the lines you want in the output with the option -w, but if this is too small, the output may look bad.

The fold command is useful, for example, when you have saved a word processor document as plain text. In the text file, each paragraph will be a single line. A command such as fold -w 76 file.txt will break these lines sensibly.

Was this article helpful?

0 0

Post a comment