fmt is a simple text formatter which reads the concatenation of input files (or standard input if none are given) and produces on standard output a version of its input with lines as close to the goal length as possible without exceeding the maximum. The goal length defaults to 65 and the maximum to 10 more than the goal length.
Alternatively, a single width parameter can be specified either by prepending a hyphen to it or by using -w. For example, “fmt -w 72”, “fmt -72”, and “fmt 72 72” all produce identical output. The spacing at the beginning of the input lines is preserved in the output, as are blank lines and interword spacing. Lines are joined or split only at white space; that is, words are never joined or hyphenated.
The options are as follows:
-c
Center the text, line by line. In this case, most of the other options are ignored; no splitting or joining of lines is done.
-dchars
Treat chars (and no others) as sentence-ending characters. By default the sentence-ending characters are full stop (‘.’), question mark (‘?’), and exclamation mark (‘!’). Remember that some characters may need to be escaped to protect them from the shell.
-lnumber
Replace multiple spaces with tabs at the start of each output line, if possible. number spaces will be replaced with one tab.
-m
Try to format mail header lines contained in the input sensibly.
-n
Format lines beginning with a ‘.’ (dot) character. Normally, fmt does not fill these lines, for compatibility with troff and nroff.
-p
Allow indented paragraphs. Without the -p flag, any change in the amount of whitespace at the start of a line results in a new paragraph being begun.
-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).
-tnumber
Assume that the input files' tabs assume number spaces per tab stop. The default is 8.
fmt is meant to format mail messages prior to sending, but may also be useful for other simple tasks. For instance, within an editor such as vi(1), the following command will reformat a paragraph, evening the lines:
!}fmt
Environment
LC_CTYPE
The character encoding locale(1). It decides which byte sequences form characters and what their display width is. If unset or set to "C", "POSIX", or an unsupported value, each byte except the tab is treated as a character of display width 1.
Exit status
The fmt utility exits 0 on success, and >0 if an error occurs. The latter happens with invalid options, insufficient memory, or when an input file is not found or not readable. The >0 exit value is the sum of all errors up to a maximum of 127; more errors may occur but the counter will only increment to this number.
Releases
61 releases since OpenBSD 2.1; the text changed 16 times.
-c since OpenBSD 2.4;
-d since OpenBSD 2.4;
-l since OpenBSD 2.4;
-m since OpenBSD 2.4;
-n since OpenBSD 3.1;
-p since OpenBSD 2.4;
-s since OpenBSD 2.4;
-t since OpenBSD 2.4.