Format report.txt for printing with page breaks.
Add the heading Monthly Report to each page without changing the file.
Which command is appropriate?
pr formats text into print-oriented pages, and -h sets the page heading.
Detailed explanation
fmt -w 60 report.txtIncorrect. fmt reflows paragraphs to a width but does not add page headers.
Incorrect. fmt reflows paragraphs to a width but does not add page headers.
head -n 60 report.txtIncorrect. head displays only an initial portion and does not paginate the whole file.
Incorrect. head displays only an initial portion and does not paginate the whole file.
pr -h 'Monthly Report' report.txtCorrect. pr -h 'Monthly Report' report.txt supplies the page heading.
Correct. pr -h 'Monthly Report' report.txt supplies the page heading.
nl -ba report.txtIncorrect. nl numbers lines but does not produce print page layout.
Incorrect. nl numbers lines but does not produce print page layout.
Try it yourself
An example you can run in a temporary verification environment.
printf 'line1\nline2\n' | pr -h 'Monthly Report' | sed -n '1,4p'Expected result
先頭付近に日付、Monthly Report、ページ番号を含む見出しKey points
- pr means print format
- -h sets the header
- Output is paginated
Notes
- Environment: GNU coreutils 9.x / 標準入力
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.