$linuxjunkies
>

pr(1)

Format text files for printing with pagination, headers, footers, and multi-column layouts.

UbuntuDebianFedoraArch

Synopsis

pr [OPTION]... [FILE]...

Description

pr prepares text files for printing or display by adding headers, footers, page numbers, and margins. It can arrange output in multiple columns, apply line numbering, and handle page breaks intelligently.

By default, pr reads from standard input or specified files and outputs formatted pages with a header showing filename, date, and page number. Each page is separated by a form feed character.

Common options

FlagWhat it does
-nnumber all lines; use -nN to set number width
-ddouble-space the output (skip blank lines)
-h HEADERreplace filename with custom header string
-l LINESset page length in lines (default 66)
-w WIDTHset page width in characters (default 72)
-mprint files side-by-side in columns
-tsuppress page headers and footers
-ppause before each page (for interactive viewing)
-o MARGINset left margin in spaces
+PAGEstart printing from PAGE number
-COLUMNSprint in COLUMNS columns; separate by spaces not tabs

Examples

Format document.txt with headers and footers, then send to printer

pr document.txt | lpr

Add line numbers to report.txt with 50-line pages, save to file

pr -n -l 50 report.txt > report_formatted.txt

Display data.txt in 3 columns with 132-character page width

pr -3 -w 132 data.txt

Print file1.txt and file2.txt side-by-side with custom header

pr -h 'Monthly Report' -m file1.txt file2.txt

Add line numbers without headers, footers, or page formatting

pr -t -n file.txt

Start printing from page 5 of document.txt

pr +5 document.txt

Double-space output with 4-space left margin

pr -d -o 4 input.txt

Format with 40-line pages and 80-character width

pr -l 40 -w 80 long_file.txt > split.txt

Related commands