- Fmt (Unix)
The fmt command in
Unix is used to format human language text. It has been traditionally used to reformat email messages after composition and prior to delivery. Its syntax is similar among various Unixes, but not identical. Fmt attempts to break, fill and join input lines to produce globally optimal, balanced output with the lengths of each line approaching the target width given by user as closely as possible, rather than wraps the input lines exactly as fold (fromGNU Core Utilities ) does.In most implementations of fmt, the
word wrap optimization procedure usually requires two criteria: the target output line width, and the maximum acceptable line width which should be larger than the previous one to give room for optimization, although it might be not always possible to give these two options simultaneously. For example,GNU fmt can only accept the maximum width option, which is given by '-w' switch, or directly '-digits' as the first command line option for compatibility. See the Solaris man page for fmt [ cite web | url = http://docs.sun.com/app/docs/doc/816-5165/fmt-1?l=en&a=view&q=fmt | title = Solaris 10 Reference Manual Collection | publisher = Sun] andFreeBSD manual entry for fmt [ cite web | url = http://www.freebsd.org/cgi/man.cgi?query=fmt&sektion=1&apropos=0&manpath=FreeBSD+6.2-RELEASE | title = FreeBSD General Commands Manual | publisher = FreeBSD] for detailed examples, and compare with the latest documentation of GNU fmt utility [ cite web | url = http://www.gnu.org/software/coreutils/manual/html_node/fmt-invocation.html | title = GNU Coreutils Documentation | publisher = FSF] included by mostLinux distributions . Please also refer to thePlan 9 fmt man page [ cite web | url = http://plan9.bell-labs.com/magic/man2html/1/fmt | title = Plan 9 /sys/man/1/fmt | publisher = Lucent Technologies | date = 2007] .Example
Given text like this as input:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur dignissimvenenatis pede. Quisque dui dui, ultricies ut, facilisis non, pulvinar non,purus. Duis quis arcu a purus volutpat iaculis. Morbi id dui in diam ornaredictum. Praesent consectetuer vehicula ipsum. Praesent tortor massa, congue et,ornare in, posuere eget, pede.Vivamus rhoncus. Quisque lacus. In hac habitasse platea dictumst. Nullam mauristellus, sollicitudin non, semper eget, sodales non, pede. Phasellus variusullamcorper libero. Fusce ipsum lorem, iaculis nec, vulputate vitae, suscipitvel, tortor. Cras varius.
Nullam fringilla pellentesque orci. Nulla eu ante pulvinar velit rhoncuslacinia. Morbi fringilla lacus quis arcu. Vestibulum sem quam, dapibus in,fringilla ut, venenatis ut, neque.
After passing this through
fmt -w 50
, the width of each line is at most 50 characters and the text flows within this constraint:Lorem ipsum dolor sit amet, consectetueradipiscing elit. Curabitur dignissim venenatispede. Quisque dui dui, ultricies ut, facilisisnon, pulvinar non, purus. Duis quis arcu apurus volutpat iaculis. Morbi id dui in diamornare dictum. Praesent consectetuer vehiculaipsum. Praesent tortor massa, congue et, ornarein, posuere eget, pede.Vivamus rhoncus. Quisque lacus. In hachabitasse platea dictumst. Nullam mauris tellus,sollicitudin non, semper eget, sodales non,pede. Phasellus varius ullamcorper libero. Fusceipsum lorem, iaculis nec, vulputate vitae,suscipit vel, tortor. Cras varius.
Nullam fringilla pellentesque orci. Nulla eu antepulvinar velit rhoncus lacinia. Morbi fringillalacus quis arcu. Vestibulum sem quam, dapibus in,fringilla ut, venenatis ut, neque.
See also
*
List of Unix commands References
Wikimedia Foundation. 2010.