Fmt (Unix)
Encyclopedia
The fmt command in Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 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 as closely as possible, rather than wrapping the input lines exactly as fold
Fold (Unix)
Fold is a Unix command used for making a file with long lines more readable on a limited width terminal. Most Linux terminals have a default screen width of 80, and therefore reading files with long lines could get annoying. The fold command puts a line feed every X characters if it doesn't...

(from GNU Core Utilities
GNU Core Utilities
The GNU Core Utilities or coreutils is a package of GNU software containing many of the basic tools, such as cat, ls, and rm, needed for Unix-like operating systems...

) does.

In most implementations of fmt, the word wrap
Word wrap
In text display, line wrap is the feature of continuing on a new line when a line is full, such that each line fits in the viewable window, allowing text to be read from top to bottom without any horizontal scrolling....

 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). It might be not always possible to give these two options simultaneously. For example, GNU
GNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...

 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 and FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...

 manual entry for fmt for detailed examples, and compare with the latest documentation of GNU fmt utility included by most Linux distributions. Please also refer to the Plan 9
Plan 9
Plan 9 may refer to:* Plan 9 from Outer Space, a 1959 science fiction film directed by Ed Wood, Jr.* Plan 9 from Outer Space , based on the filmMusic:* Plan 9 , a psychedelic rock band from Rhode Island...

 fmt man page.

Unlike par
Par (command)
The computer program par is a text formatting utility for Unix, written by Adam M. Costello as a replacement for the fmt command.Par reformats paragraphs of text to fit into a given line length optimally, keeping prefixes and suffixes intact, which is useful for formatting source code comments...

, fmt has no Unicode support, and does not support text justification.

Example

Given text like this as input:


Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur dignissim
venenatis pede. Quisque dui dui, ultricies ut, facilisis non, pulvinar non,
purus. Duis quis arcu a purus volutpat iaculis. Morbi id dui in diam ornare
dictum. Praesent consectetuer vehicula ipsum. Praesent tortor massa, congue et,
ornare in, posuere eget, pede.

Vivamus rhoncus. Quisque lacus. In hac habitasse platea dictumst. Nullam mauris
tellus, sollicitudin non, semper eget, sodales non, pede. Phasellus varius
ullamcorper libero. Fusce ipsum lorem, iaculis nec, vulputate vitae, suscipit
vel, tortor. Cras varius.

Nullam fringilla pellentesque orci. Nulla eu ante pulvinar velit rhoncus
lacinia. 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, consectetuer
adipiscing elit. Curabitur dignissim venenatis
pede. Quisque dui dui, ultricies ut, facilisis
non, pulvinar non, purus. Duis quis arcu a
purus volutpat iaculis. Morbi id dui in diam
ornare dictum. Praesent consectetuer vehicula
ipsum. Praesent tortor massa, congue et, ornare
in, posuere eget, pede.

Vivamus rhoncus. Quisque lacus. In hac
habitasse platea dictumst. Nullam mauris tellus,
sollicitudin non, semper eget, sodales non,
pede. Phasellus varius ullamcorper libero. Fusce
ipsum lorem, iaculis nec, vulputate vitae,
suscipit vel, tortor. Cras varius.

Nullam fringilla pellentesque orci. Nulla eu ante
pulvinar velit rhoncus lacinia. Morbi fringilla
lacus quis arcu. Vestibulum sem quam, dapibus in,
fringilla ut, venenatis ut, neque.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK