While working in the Linux terminal, you may run into situations where you need to explore a large text file for a long documentation file. One way to achieve this is to paginate the text file. So in this article, we will discuss how you can perform pagination on a text file in Linux.
The formfeed character, ASCII C-l or octal code 014, is the delimiter used to paginate text. When you send text with a formfeed character to the printer, the current page being printed is ejected and a new page begins—thus, you can paginate a text file by inserting formfeed characters at a place where you want a page break to occur.
To insert formfeed characters in a text file, use the pr filter.
Give the ‘-f’ option to omit the footer and separate pages of output with the formfeed character, and use ‘-h ""’ to output a blank header (otherwise, the current date and time, file name, and current page number are output at the top of each page).
To paginate the file ‘listings’ and write the output to a file called ‘listings.page’, type:
$ pr -f -h "" listings > listings.page
By default, pr outputs pages of 66 lines each. You can specify the page length as an argument to the ‘-l’ option.
To paginate the file ‘listings’ with 43-line pages, and write the output to a file called ‘listings.page’, type:
$ pr -f -h "" -l 43 listings > listings.page
NOTE: If a page has more lines than a printer can fit on a physical sheet of paper, it will automatically break the text at that line as well as at the places in the text where there are formfeed characters.
The pr tool is a general-purpose page formatter and print-preparation utility. By default, pr outputs text in pages of 66 lines each, with headers at the top of each page containing the date and time, file name, and page number, and footers containing five blank lines.
To print the file ‘duchess’ with the default pr preparation, type:
$ pr duchess | lpr
You can also use pr to put text in columns—give the number of columns to output as an argument. Use the ‘-t’ option to omit the printing of the default headers and footers.
To print the file ‘news.update’ in four columns with no headers or footers, type:
$ pr -4 -t news.update | lpr
The following list describes some of pr’s options; see the pr info for a complete description of its capabilities.
If you like to learn more about Linux, taking the following courses is highly recommended:
Here is the list of our 9 free self-paced courses that are highly recommended:
If you like to learn more about Linux, take the following live Linux classes is highly recommended:
If you like to learn more about Linux, reading the following articles and tutorials is highly recommended:
We offer private custom tutoring classes both online and in DC, MD and VA for almost all of our courses or bootcamps. Give us a call or email us to discuss your needs.
$50 Limited OfferREGISTER NOW