xref: /freebsd/usr.bin/fmt/fmt.1 (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1.\" Copyright (c) 1980, 1990, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     @(#)fmt.1	8.1 (Berkeley) 6/6/93
29.\" $FreeBSD$
30.\"
31.\" Modified by Gareth McCaughan to describe the new version of `fmt'
32.\" rather than the old one.
33.Dd October 29, 2020
34.Dt FMT 1
35.Os
36.Sh NAME
37.Nm fmt
38.Nd simple text formatter
39.Sh SYNOPSIS
40.Nm
41.Op Fl cmnps
42.Op Fl d Ar chars
43.Op Fl l Ar num
44.Op Fl t Ar num
45.Op Ar goal Oo Ar maximum Oc | Fl Ns Ar width | Fl w Ar width
46.Op Ar
47.Sh DESCRIPTION
48The
49.Nm
50utility is a simple text formatter which reads the concatenation of input
51files (or standard input if none are given) and produces on standard
52output a version of its input with lines as close to the
53.Ar goal
54length
55as possible without exceeding the
56.Ar maximum .
57The
58.Ar goal
59length defaults
60to 65 and the
61.Ar maximum
62to 10 more than the
63.Ar goal
64length.
65Alternatively, a single
66.Ar width
67parameter can be specified either by prepending a hyphen to it or by using
68.Fl w .
69For example,
70.Dq Li fmt -w 72 ,
71.Dq Li fmt -72 ,
72and
73.Dq Li fmt 72 72
74all produce identical output.
75The spacing at the beginning of the input lines is preserved in the output,
76as are blank lines and interword spacing.
77Lines are joined or split only at white space; that is, words are never
78joined or hyphenated.
79.Pp
80The options are as follows:
81.Bl -tag -width indent
82.It Fl c
83Center the text, line by line.
84In this case, most of the other
85options are ignored; no splitting or joining of lines is done.
86.It Fl m
87Try to format mail header lines contained in the input sensibly.
88.It Fl n
89Format lines beginning with a
90.Ql \&.
91(dot) character.
92.It Fl p
93Allow indented paragraphs.
94Without the
95.Fl p
96flag, any change in the amount of whitespace at the start of a line
97results in a new paragraph being begun.
98.It Fl s
99Collapse whitespace inside lines, so that multiple whitespace
100characters are turned into a single space.
101(Or, at the end of a
102sentence, a double space.)
103.It Fl d Ar chars
104Treat the
105.Ar chars
106(and no others) as sentence-ending characters.
107By default the
108sentence-ending characters are full stop
109.Pq Ql \&. ,
110question mark
111.Pq Ql \&?
112and exclamation mark
113.Pq Ql \&! .
114Remember that some characters may need to be
115escaped to protect them from your shell.
116.It Fl l Ar number
117Replace multiple spaces with tabs at the start of each output
118line, if possible.
119Each
120.Ar number
121spaces will be replaced with one tab.
122The default is 8.
123If
124.Ar number
125is 0, spaces are preserved.
126.It Fl t Ar number
127Assume that the input files' tabs assume
128.Ar number
129spaces per tab stop.
130The default is 8.
131.El
132.Pp
133The
134.Nm
135utility
136is meant to format mail messages prior to sending, but may also be useful
137for other simple tasks.
138For instance,
139within visual mode of the
140.Xr ex 1
141editor (e.g.,
142.Xr vi 1 )
143the command
144.Pp
145.Dl \&!}fmt
146.Pp
147will reformat a paragraph,
148evening the lines.
149.Sh ENVIRONMENT
150The
151.Ev LANG , LC_ALL
152and
153.Ev LC_CTYPE
154environment variables affect the execution of
155.Nm
156as described in
157.Xr environ 7 .
158.Sh EXAMPLES
159Center the text in standard input:
160.Bd -literal -offset indent
161$ echo -e 'The merit of all things\enlies\enin their difficulty' | fmt -c
162                     The merit of all things
163                               lies
164                       in their difficulty
165.Ed
166.Pp
167Format the text in standard input collapsing spaces:
168.Bd -literal -offset indent
169$ echo -e 'Multiple   spaces    will be collapsed' | fmt -s
170Multiple spaces will be collapsed
171.Ed
172.Sh SEE ALSO
173.Xr fold 1 ,
174.Xr mail 1
175.Sh HISTORY
176The
177.Nm
178command appeared in
179.Bx 3 .
180.Pp
181The version described herein is a complete rewrite and appeared in
182.Fx 4.4 .
183.Sh AUTHORS
184.An Kurt Shoens
185.An Liz Allen
186(added
187.Ar goal
188length concept)
189.An Gareth McCaughan
190.Sh BUGS
191The program was designed to be simple and fast \- for more complex
192operations, the standard text processors are likely to be more appropriate.
193.Pp
194When the first line of an indented paragraph is very long (more than
195about twice the goal length), the indentation in the output can be
196wrong.
197.Pp
198The
199.Nm
200utility is not infallible in guessing what lines are mail headers and what
201lines are not.
202