pr
Quick Reference
Command Name:
pr
Category:
text processing
Platform:
linux
Basic Usage:
Common Use Cases
- 1
Text pagination
Format text data for printing
- 2
Report generation
Generate reports with page breaks and headers
- 3
Scripting
Use in shell scripts to format text data programmatically
- 4
Text processing
Manipulate text data in pipelines and scripts
Syntax
pr [OPTION]... [FILE]...
Options
Option | Description |
---|---|
+FIRST_PAGE[:LAST_PAGE] | Begin printing with page FIRST_PAGE and stop with LAST_PAGE |
-COLUMN | Output COLUMN columns and print columns down |
-a | Print columns across rather than down (used with -COLUMN) |
-d | Double space the output |
-h HEADER | Use a centered HEADER instead of filename in page header |
-l PAGE_LENGTH | Set the page length to PAGE_LENGTH (66) lines |
-m | Print all files in parallel, one in each column |
-n | Number lines |
-o MARGIN | Offset each line with a margin MARGIN spaces wide |
-t | Omit page headers and trailers |
-w PAGE_WIDTH | Set page width to PAGE_WIDTH (72) characters |
Examples
How to Use These Examples
The examples below show common ways to use the pr
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
pr filename.txt
Formats the file with default settings, adding a header (date, time, filename, and page number) and pagination. Each page is 66 lines by default, with headers and blank lines.
pr -h "Custom Header" filename.txt
Format the file with a custom header instead of the default filename. This is useful when you want more descriptive page headers.
pr -l 50 filename.txt
Sets the page length to 50 lines instead of the default 66. This helps adjust the output to different paper sizes or printing requirements.
pr -2 filename.txt
Format the output in 2 columns. The text is split across columns from top to bottom, which is useful for creating more compact printouts.
Advanced Examples:
pr -m file1.txt file2.txt
Merge two files side-by-side with a separator between them. This is useful for comparing two text files or creating parallel presentations of content.
pr -n -h "Source Code" sourcefile.c
Number all lines and add a custom header. This is helpful when printing source code for review or reference.