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.
Incorrect. 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.
Incorrect. pr controls print formatting and page width rather than paragraph reflow.
split -l 40 prose.txtIncorrect. split divides input into files by line count.
Incorrect. split divides input into files by line count.
fmt -w 40 prose.txtCorrect. fmt -w 40 prose.txt reformats paragraphs toward 40 columns.
Correct. 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 / 標準入力
- 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.