Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Google   


Unix fmt commnad

News Syntax Recommended Links Sorting algorithms Recommended Papers Rcut Reference Pipes
Perl re-implemenations uniq sort tr AWK Tips Humor Etc

You can use the fmt command to format messages before sending them to another user via mail. Another use is for formatting memos or comments in source code. To extract comments for formatiing yu need to write small Perl scripts that first creates separate files for each comment block instering placehoders into the original source, then format them with fmt and after that insert them back replacing placeholders created on the first step.

The external fmt command performs simple right margin justification text formatting. A list of files are read in and the input is massaged to be as close as possible to 72 columns wide. Spacing at the beginning of input lines, blank lines, and spacing between words are left unmodified. If no files are provided as arguments, fmt reads from the standard input.

You can pipe the commends block via tr command to trim spacing (option delete).

The fmt command was originally written to format messages before mailing, but it may be useful for other simple formatting tasks. It is useful for formatting sections of text printed by a shell script.

A most popular use of fmt command is from vi editor. Assume you have created the following file and you are on line one. The cursor is under the T of This.

     This is a brief message to the Control Unit group.
     The new hp is now on-line. To send prints to it, type lj filename.
     If you have questions contact Sys. Adm. (x480).
     The printer is located in the stock room.

Now type !} fmt and press Return. This command sends the paragraph to the fmt command as standard input. Then vi reads the standard output of the fmt command and replaces the paragraph with the formatted output. Your paragraph now resembles the following screen.

     This is a brief message to the Control Unit group. The new hp is now on-line. To send prints to it, type lj
     filename. If you have questions contact Sys. Adm. (x480). The printer is located in the stock room.

fmt is limited in what it can do, but it is adequate for comment blocks and text mail messages  formatting.

 The general format of the fmt command.

     fmt [ -cs ] [ -w width ] [ file_list ]

There are just three options:

-c Use crown margin mode. The indentation of the first two lines is preserved, with the rest of the paragraph aligned with the second line.
-s Do not join short lines to form longer ones. Only split lines. This prevents short lines, such as examples of program code, from being combined.
-w width Format output text up to width columns. The default width is 72 columns.

Reference

OPTIONS

OPERANDS

ENVIRONMENT VARIABLES

ATTRIBUTES

 

 


Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

Last modified: September 15, 2008