pr - macOS


Overview

The pr command in macOS is used for pagination and setup of text files for printing. It inserts form feeds, page numbers, date, file name, and time into text files, allowing for easy conversion into printed documents.

Syntax

pr [options] <file>

Options/Flags

  • -a: Add page number to each line.
  • -c: Page length (default: 60).
  • -d: Specify date format (default: Today).
  • -f: Specify output file (default: standard output).
  • -h: Print help message and exit.
  • -i: Ignore blank pages.
  • -l: Page number format (e.g., for Roman numerals, use -l R).
  • -n: Page numbering format (e.g., -n 2-7 starts page numbering at 2 and ends at 7).
  • -t: Page title (default: empty).
  • -w: Page width (default: 79).

Examples

Insert page numbers and headers:

pr -a -f output.txt input.txt

Set page length to 50 and add filename and date:

pr -c 50 -d "%Y-%m-%d" -t "File: input.txt" input.txt

Create a header with custom text:

pr -t "Confidential Document" input.txt

Common Issues

Missing page numbering:
Ensure the -a option is specified.

Incorrect page length:
Adjust the -c option to the desired page length.

Date not formatted as expected:
Use the -d option to specify the desired date format (e.g., -d "%d/%m/%Y" for DD/MM/YY).

Integration

With lp (printing):

pr -f input.txt | lp

With awk (count lines):

awk '{line++} END {print line}' | pr
  • fmt: Formats text without pagination.
  • lp: Sends files to a printer.
  • more: Paginates text files interactively.