Jump to content

fmt

From RaySoft

fmt fills and joins lines to produce output lines of (at most) a given number of characters.[1]

Documentation

Syntax

fmt [PARAMETER ...] [FILE ...]

Parameters

General
The following parameters can be used with all version of fmt:
NOTE:
The BSD version only supports the short form (e.g. -w) of these parameters!
-WIDTH, -w WIDTH, --width=WIDTH
Fill output lines up to WIDTH characters (default 75).
BSD
The following parameters can be used with the BSD version of fmt:
-s
Collapse whitespace inside lines, so that multiple whitespace characters are turned into a single space. (Or, at the end of a sentence, a double space.)
GNU
The following parameters can be used with the GNU version of fmt:
-u, --uniform-spacing
One space between words, two after sentences.

Examples

Scale to unit
fmt --width=50 <<EOT
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
EOT

Output:

Lorem ipsum dolor sit amet, consetetur sadipscing
elitr, sed diam nonumy eirmod tempor invidunt
ut labore et dolore magna aliquyam erat, sed
diam voluptua.

References

  1. Project contributors. "fmt: Reformat paragraph text." GNU project. https://www.gnu.org/software/coreutils/manual/html_node/fmt-invocation.html (accessed 19.08.2025)