The pr
command is used to convert a text file into a format suitable for printing. It is a Unix command-line utility that paginates or columnates text files for printing. The command can be used to add headers and footers, adjust margins, and control page breaks.
Overview
The basic syntax for the pr
command is:
pr [options] [filename]
The filename
parameter specifies the name of the file to be processed. If no filename is specified, the command reads from standard input.
Here are some examples of how to use the pr
command:
- To paginate a file with 60 lines per page and print it to the standard output:
pr -l 60 filename.txt
- To columnate a file with 3 columns and print it to the standard output:
pr -3 filename.txt
- To add a header and footer to a file and print it to the standard output:
pr -h "Header text" -f "Footer text" filename.txt
- To adjust the page width and print a file to the standard output:
pr -w 80 filename.txt
Options
Here are the available options for the pr
command:
Option | Description |
---|---|
-h header |
Specifies the header text to be printed at the top of each page. |
-f footer |
Specifies the footer text to be printed at the bottom of each page. |
-l lines |
Specifies the number of lines per page. |
-w width |
Specifies the page width in characters. |
-m margin |
Specifies the left and right margins in characters. |
-o offset |
Specifies the number of lines to skip before starting to print. |
-t |
Prints a header at the beginning of each page with the filename, date, and time. |
-s |
Collapses multiple blank lines into a single blank line. |
-a |
Prints all pages, including empty ones. |
-d |
Double-spaces the output. |
-e |
Prints a dollar sign at the end of each line. |
-i |
Ignores control characters. |
-n |
Prints line numbers. |
-p |
Forces a page break before each new file. |
-T |
Prints tabs as spaces. |
-x |
Prints each line twice. |
-1 |
Prints one column per page. |
-2 |
Prints two columns per page. |
-3 |
Prints three columns per page. |
Troubleshooting tips
- If the output is not as expected, check the options and parameters used with the command.
- If the file is not found, check the file path and permissions.
- If the command hangs or does not complete, try using the
Ctrl+C
key combination to stop the command.
Notes
- The
pr
command is commonly used with thelp
command to send the output to a printer. - The
pr
command can be used to format and print source code files for easier readability. - The
pr
command can be used to create a table of contents for a large document by using the-t
option.