Reformat paragraphs in prose.txt at word boundaries to a target width of 40 characters.
Do not split mechanically at fixed character offsets.
Which command is appropriate?
fmt joins and wraps paragraph lines at word boundaries. The -w option sets the target width.
Detailed explanation
fold -w 40 prose.txtIncorrect. fold wraps at a width but does not reflow paragraphs like fmt.
pr -w 40 prose.txtIncorrect. pr controls print formatting and page width rather than paragraph reflow.
split -l 40 prose.txtIncorrect. split divides input into files by line count.
fmt -w 40 prose.txtCorrect. fmt -w 40 prose.txt reformats paragraphs toward 40 columns.
Try it yourself
An example you can run in a temporary verification environment.
printf 'one two three four five six seven\n' | fmt -w 12Expected result
各行がおおむね12文字以内となる単語単位の折り返しKey points
- fmt formats paragraphs
- -w sets the width
- split divides files rather than reflowing text
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
fold changes presentation by inserting line breaks; it does not necessarily change the underlying words or records.
Check the side effect
Use ASCII input for byte-width tests and consider multibyte characters separately.