Fmt (Unix)

Last updated
fmt
Original author(s) AT&T Bell Laboratories
Developer(s) Various open-source and commercial developers
Operating system Unix, Unix-like, Plan 9, Inferno
Platform Cross-platform
Type Command

The fmt command in Unix, Plan 9, Inferno, and Unix-like operating systems is used to format natural language text for humans to read.

Contents

Overview

The command 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 (from GNU 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). It might be not always possible to give these two options simultaneously. For example, early versions of 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 (later versions use -g to specify the goal width and -w for the maximum width). See the Solaris man page for fmt [1] and FreeBSD manual entry for fmt [2] for detailed examples, and compare with the latest documentation of GNU fmt utility [3] included by most Linux distributions. See also the Plan 9 fmt man page. [4]

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

The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities. [5]

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. 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. 

See also

Related Research Articles

C (programming language) General-purpose programming language

C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, with a static type system. By design, C provides constructs that map efficiently to typical machine instructions. It has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computer architectures that range from supercomputers to PLCs and embedded systems.

Latin Indo-European language of the Italic branch

Latin is a classical language belonging to the Italic branch of the Indo-European languages. Latin was originally a dialect spoken in the lower Tiber area around present-day Rome, and through the power of the Roman Republic, became the dominant language in Italia and subsequently throughout the realms of Roman Empire. Even after the fall of Western Rome, Latin was the common language of international communication, science, scholarship and academia in Europe until well into the 18th century, when other regional vernaculars supplanted it in common academic and political usage, and it eventually became a dead language in the modern linguistic definition.

TeX, stylized within the system as TeX, is a typesetting system which was designed and written by Donald Knuth and first released in 1978. TeX is a popular means of typesetting complex mathematical formulae; it has been noted as one of the most sophisticated digital typographical systems.

printf format string refers to a control parameter used by a class of functions in the input/output libraries of C and many other programming languages. The string is written in a simple template language: characters are usually copied literally into the function's output, but format specifiers, which start with a % character, indicate the location and method to translate a piece of data to characters.

In the written form of many languages, an indentation or indent is an empty space at the beginning of a line to signal the start of a new paragraph. Many computer languages have adopted this technique to designate "paragraphs" or other logical blocks in the program.

In word processing and digital typesetting, a non-breaking space,  , also called NBSP, required space, hard space, or fixed space, is a space character that prevents an automatic line break at its position. In some formats, including HTML, it also prevents consecutive whitespace characters from collapsing into a single space.

Comparison of command shells Wikimedia list article

A command shell is a command-line interface to interact with and manipulate a computer's operating system.

The zero-width space (), abbreviated ZWSP, is a non-printing character used in computerized typesetting to indicate word boundaries to text-processing systems in scripts that do not use explicit spacing, or after characters that are not followed by a visible space but after which there may nevertheless be a line break. It is also used with languages without visible space between words, for example, Japanese. Normally, it is not a visible separation, but it may expand in passages that are fully justified.

fold is a Unix command used for making a file with long lines more readable on a limited width computer terminal by performing a line wrap.

References

  1. "Solaris 10 Reference Manual Collection". Sun.
  2. "FreeBSD General Commands Manual". FreeBSD.
  3. "GNU Coreutils Documentation". FSF.
  4. "Plan 9 /sys/man/1/fmt". Alcatel-Lucent. 2020.
  5. "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.