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.
head -n 60 report.txtIncorrect. 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.
nl -ba report.txtIncorrect. 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 / 標準入力
- Use small, disposable text streams when testing filters.
- Locale, encoding, and GNU/POSIX implementation details can affect edge cases.
Foundation review
Place the operation
pr is a formatter for readable paper-style output, not a general text concatenator.
Check the side effect
Inspect a short output and verify where headings and page boundaries occur.