Skip to content

pr MacOS Command Guide

The MacOS pr command is used for file printing and formatting. It allows users to display files in a specified format, with options for specifying page layout, pagination, and other formatting features. By using the pr command, users can customize the appearance of files when printing or displaying them on the terminal. This command is particularly useful for organizing and presenting text files in a readable and structured manner. It provides flexibility in how files are displayed, making it easier to view and analyze content. With the pr command, users can adjust the number of columns, page length, headers, footers, and more to suit their needs. Additionally, the pr command offers options for skipping header lines, numbering lines, and specifying delimiter characters. By mastering the pr command, users can efficiently format and print files in the desired layout and style.

pr Syntax:

Terminal window
pr [option] [parameter]

Options:

OptionDescription
-dDouble-spaced output
-hSuppress headers
-lPaginate by line length
-mPaginate by page length
-nSpecify number of columns
-tDo not expand tabs

Parameters:

ParameterDescription
fileSpecifies the file to print

pr Command Samples:

Merge Two Files

Terminal window
pr file1.txt file2.txt > merged_file.txt

Merge the contents of file1.txt and file2.txt into a new file named merged_file.txt.

Format Output with Column Width

Terminal window
pr -t -w 100 file.txt

Format the output of file.txt with a tabular layout and set the column width to 100 characters.

Change Page Length

Terminal window
pr -l 40 file.txt

Change the number of lines per page to 40 when printing the contents of file.txt.

Number Lines

Terminal window
pr -n file.txt

Number each line when printing the contents of file.txt.

Suppress Header and Trailer

Terminal window
pr -h "" -F "" file.txt

Suppress the header and trailer when printing the contents of file.txt.

Set Page Width

Terminal window
pr -w 120 file.txt

Set the page width to 120 characters when printing the contents of file.txt.

Use Multiple Delimiters

Terminal window
pr -d ":,;" file.csv

Utilize multiple delimiters (”:”, ”,”, ”;”) when processing the contents of file.csv.

pr FAQ:

How do I use pr in MacOS?

To use the pr command in MacOS, execute the following command:

Terminal window
pr --columns=3 example.txt

What is the purpose of pr command in MacOS?

The pr command in MacOS is used for pagination of files for printing or display purposes.

How can I specify the number of columns for output in pr command?

To specify the number of columns for output in the pr command, use the --columns option followed by the desired value. For example:

Terminal window
pr --columns=4 example.txt

How to add a header to the output generated by pr command in MacOS?

To add a header to the output generated by the pr command in MacOS, use the -h option followed by the header text. For example:

Terminal window
pr -h "Header Text" example.txt

Can I customize page width and height in pr command for MacOS?

Yes, you can customize the page width and height in the pr command for MacOS using the -w and -l options followed by the desired values. For example:

Terminal window
pr -w 80 -l 50 example.txt

How to suppress page headers in pr command output in MacOS?

To suppress page headers in the output generated by the pr command in MacOS, use the -t option. For example:

Terminal window
pr -t example.txt

Applications of the pr command

  • Formatting text for printing
  • Adjusting column widths
  • Paginating text for readability
  • Preparing files for printing or viewing on paper