Linux/Unix – Paginating Text Files with pr
The pr command provides a quick way to format a bunch of text into a form where it can be printed. This can be particularly useful if you want to print the results of some commands, without having to open up a word processor or text editor. With pr, you can format text into pages with header information such as date, time, file name, and page number.
Here is an example:
$ dpkg-query -l | sort | pr –column=2 | less — Paginate package list in 2 cols
In this example, the rpm -qa command lists all software packages installed on your system and pipes that list to the sort command, to be sorted alphabetically. Next that list is piped to the pr command, which converts the single-column list into two columns (–columns=2) and paginates it. Finally, the less command enables you to page through the text.
Instead of paging through the output, you can send the output to a file or to a printer. Here are examples of that:
$ dpkg-query -l | sort | pr –column=2 > pkg.txt — Send pr output to a file
$ dpkg-query -l | sort | pr –column=2 | lpr — Send pr output to printer
Other text manipulation you can do with the pr command includes double-spacing the text (-d), showing control characters (-c), or offsetting the text a certain number of spaces from the left margin (for example, -o 5 to indent five spaces from the left).