Format Text for Printing with GNU pr
You will turn plain text into paginated or columnated output with GNU pr, then verify the result without sending anything to a printer. The examples cover normal page headers, compact output, line numbers, columns and side-by-side files. Allow about ten minutes. You need a shell and GNU coreutils; no elevated privileges are required unless the input or output directory is deliberately restricted.
The route
Jump straight to the step you need, or tick off Done means at the end.
1. Check the installed command
This guide follows GNU coreutils pr 9.4, installed here from the coreutils package. Check your own command before putting an option into a script:
$ command -v pr
/usr/bin/pr
$ pr --version | head -2
pr (GNU coreutils) 9.4
Copyright (C) 2023 Free Software Foundation, Inc.
GNU pr reads named files, or standard input when there is no file or the file name is -. It writes formatted text to standard output. It does not edit the input file.
Checkpoint
If command -v pr finds a different implementation, read that implementation's manual page before relying on GNU-specific details such as the long options shown here.
2. See the default paginated form
Create a small input file, or substitute an existing text file you want to inspect:
$ printf '%s\n' alpha bravo charlie delta echo foxtrot > input.txt
$ pr input.txt | sed -n '1,8p'
2026-09-26 12:01 input.txt Page 1
alpha
bravo
charlie
The exact header spacing and time will differ. By default, GNU pr uses a 66-line page, including a header and trailer, leaving 56 lines of text. The header contains the date, file name and page number. The first two blank lines in the sample are part of the five-line header structure.
Do not treat the displayed date as a reliable document timestamp. It is generated when the command runs. If a file name contains spaces, quote it as usual:
$ pr '/path/to/meeting notes.txt' > meeting-notes.txt
The redirection creates or truncates meeting-notes.txt before pr starts. If that destination already contains useful output, do not run this command blindly. Choose a new name, or use a temporary destination and replace the old file only after checking it.
3. Remove headers for clean text
Use -t, also called --omit-header, when you want the input content without page headers or trailers:
$ pr -t input.txt
alpha
bravo
charlie
delta
echo
foxtrot
This is useful for a quick column layout or a pipeline where a print header would become misleading. It does not remove form-feed characters already present in the input. Use -T when you also want to eliminate input pagination:
$ pr -T input.txt > unpaginated.txt
$ test -s unpaginated.txt && echo 'output exists'
output exists
-T also omits headers and trailers. The output file is still a new file; the input remains unchanged.
4. Number lines for review
Add -n to put a line number at the start of each output line. The default uses five digits followed by a tab:
$ pr -t -n input.txt
1 alpha
2 bravo
3 charlie
4 delta
5 echo
6 foxtrot
These numbers are generated by pr; they are not inserted into the source file. To start at a different number, use -N:
$ pr -t -N 100 input.txt | sed -n '1,2p'
100 alpha
101 bravo
Line numbering is a presentation choice. If you are preparing a file for another program, check that the receiving program expects the added prefix rather than treating it as data.
5. Arrange one file in columns
Use -2 for two columns. Without -a, pr fills columns down the page before moving to the next column:
$ pr -t -2 input.txt
alpha delta
bravo echo
charlie foxtrot
The large gap is normal: GNU pr reserves space within the default 72-character width. Add -a when the input should run across each row instead:
$ pr -t -a -2 input.txt
alpha bravo
charlie delta
echo foxtrot
For a different width, use -w, but remember that it applies to multiple text-column output. -W sets the page width always and can truncate long lines. Keep long-line handling visible in scripts: truncation can lose data even though the command exits successfully.
6. Merge separate files side by side
Use -m when each input file should occupy its own column. A separator makes the result easier to inspect:
$ printf '%s\n' A1 A2 A3 > left.txt
$ printf '%s\n' B1 B2 B3 > right.txt
$ pr -t -m -s' | ' left.txt right.txt
A1 | B1
A2 | B2
A3 | B3
Files are read in parallel, so this is useful for a compact comparison. Shorter files leave empty space after their final line. By default, -m can truncate lines to fit the page width. If preserving full lines matters more than alignment, inspect the documented interaction between -J and -m before choosing a format.
7. Control the heading and page size
Use -h to replace the file name in a page header. The option changes the label, not the input:
$ printf 'one\ntwo\n' | pr -h 'stdin demo' - | sed -n '1,7p'
2026-09-26 12:01 stdin demo Page 1
one
The time and spacing vary. An empty header, -h '', is documented as a blank line, but the manual advises against using that form. Prefer -t when headers are not wanted.
-l changes the page length. Values of 10 or fewer imply -t, which is handy for a short, predictable output block:
$ pr -l 10 input.txt
alpha
bravo
charlie
delta
echo
foxtrot
For ordinary printing, leave the default page length alone unless the target printer or downstream formatter requires another size. A very small value changes the header behaviour and can distract from the content you are trying to format.
8. Verify before replacing an existing output
For a valuable destination, write to a new file first. This avoids losing the old result if the input path, options or permissions are wrong:
$ pr -t -n input.txt > formatted.txt.new
$ test -s formatted.txt.new && sed -n '1,3p' formatted.txt.new
1 alpha
2 bravo
3 charlie
$ mv formatted.txt.new formatted.txt
The mv command changes state by replacing the destination if it already exists. Run it only after the preview is correct. If the preview is wrong, leave the original alone and remove the unneeded .new file manually after checking its path. Do not use sudo to work around an uncertain path; fix the ownership or permissions deliberately, and only when you administer that directory.
9. Diagnose common mistakes
If a file cannot be opened, check the path and readability without changing anything:
$ ls -l /path/to/input.txt
$ test -r /path/to/input.txt && echo readable
readable
If output appears to lose the right side of long lines, check whether -W, a column option or the default 72-character width is truncating it. Use -J when joining full lines is the required result, then inspect the alignment because joined lines are not column-aligned. If the input is already paginated, choose between -t and -T according to whether existing form feeds should remain.
Check the exit status immediately after a command when scripting:
$ pr -t input.txt > formatted.txt
$ printf 'pr status: %s\n' "$?"
pr status: 0
A zero status means the command completed. It does not prove that the layout suits the printer, that long lines were not truncated, or that the output file is the one you intended. Inspect representative pages before sending a large job to a printer.
Done means
pr --versionidentifies the implementation you checked.- You chose headers, line numbers, columns or merged files for the actual output requirement.
- You checked width and pagination so long lines and existing form feeds are handled deliberately.
- The formatted output was previewed before any existing file was replaced.
- The source files remain unchanged, and no elevated privileges were used without a clear directory-permission reason.