Home > Text Processing & Search > pr

pr: Format text files for printing

The pr command converts text files into a format suitable for printing. It offers various formatting features such as adding page numbers, headers, dates, splitting into multiple columns, or adjusting page length. It is commonly used to make text more readable in the terminal or before printing.

Overview

pr divides the content of text files into pages, adds headers (filename, date, page number) to each page, and arranges the text into multiple columns, outputting it in a print-optimized format to standard output. It is useful for viewing file content neatly.

Key Features

  • Page separation and numbering
  • Adding custom headers
  • Arranging text into multiple columns
  • Adding line numbers
  • Merging and outputting multiple files

Key Options

The main options of the pr command help in fine-grained control over the output format and page layout.

Output Format and Layout

Generated command:

Try combining the commands.

Description:

`pr` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Examples demonstrating various ways to use the pr command.

Basic Pagination

pr my_document.txt

Divides file content into pages and adds headers for output.

Add Line Numbers and Custom Header

pr -n -h "My Report" my_document.txt

Adds numbers to each line and a header titled 'My Report' for output.

Output Two Files Side-by-Side in Two Columns

pr -m file1.txt file2.txt

Outputs the content of file1.txt and file2.txt side-by-side in two columns.

Output with 30 Lines per Page, No Header/Footer

pr -t -l 30 my_document.txt

Sets the output to 30 lines per page without headers or footers.

Process Output of Another Command via Pipe

ls -l | pr -2

Takes the output of the ls -l command and formats it into two columns using pr.

Tips & Notes

Useful tips and points to consider when using the pr command.

Using Pipes (|)

pr is very useful for processing the standard output of other commands, not just files. For example, you can use `ls -l | pr -3` to view a long list in multiple columns.

  • Pipe the output of other commands to `pr` for formatting
  • Display more information on a single screen without scrolling

Direct Output to Printer

You can pipe the output of pr directly to printer commands like `lpr` or `lp` to print formatted documents.

  • `pr file.txt | lpr`

Changing Defaults

pr defaults to a page length of 66 lines and a page width of 72 characters. You can change these values using the `-l` and `-w` options.

  • Page Length: `-l N`
  • Page Width: `-w N`

Same category commands