Linux Basics: Select Text Report Pages with GNU pr
GNU pr formats plain text for display or printing. It writes to standard output; it does not submit a print job. A chosen page length lets you extract a report segment, while column mode presents short labels compactly.
Prepare a scratch directory
Tested on Linux with GNU coreutils 9.7, GNU findutils 4.10.0, and GNU Bash 5.2.37. You need Bash, a text editor, and the utilities used below. The script creates its own temporary fixture directory and removes only that directory on exit.
Keep the same terminal open. Stop if setup fails, before saving the source:
start_dir="$PWD"
work_dir="$(mktemp -d)" || exit 1
cd -- "$work_dir" || exit 1Run the example
Save this as demonstrate-gnu-pr-page-selection.sh:
#!/usr/bin/env bash
set -euo pipefail
export LC_ALL=C
fixture_dir="$(mktemp -d)"
trap 'rm -rf -- "$fixture_dir"' EXIT
cd -- "$fixture_dir"
printf 'row-%s\n' {1..8} > report.txt
printf 'Page two, three lines per page:\n'
pr -t -l 3 +2:2 report.txt
printf 'Two columns, filled across:\n'
pr -t -2 -a -s'|' report.txt
test "$(pr -t -l 3 +2:2 report.txt | wc -l)" -eq 3Run it:
bash demonstrate-gnu-pr-page-selection.shObserved output:
Page two, three lines per page:
row-4
row-5
row-6
Two columns, filled across:
row-1|row-2
row-3|row-4
row-5|row-6
row-7|row-8Read the result
-l 3 sets a three-line page length, +2:2 selects only page two, and -t omits headers and trailers. The selected lines are therefore rows four through six. In the second command, -2 requests two columns and -a fills them across rather than down. -s chooses a single-character column separator, giving a compact display without alignment padding.
Apply it carefully
These are logical text pages, not pages from a PDF or a printer driver. Headers and trailers consume space when enabled; this fixture disables them explicitly. The short ASCII rows contain no form feeds or terminal control characters. Longer or unusual inputs need deliberate width and control-character handling. A column separator does not make the result a robust data interchange format, since source lines can contain that same character. Keep structured records in their original format and use pr for presentation.
The GNU reference documents these options and their behavior.
Clean up
Remove the saved script, return to the starting directory, and remove the empty practice directory:
rm -- demonstrate-gnu-pr-page-selection.sh
cd -- "$start_dir" || exit 1
rmdir -- "$work_dir"
unset start_dir work_dirIf the directory is not empty, inspect what remains rather than deleting unknown files.
Acknowledgements
This post was created with assistance from AI.