|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
|
| 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. |
fmt is a simple text formatter that fills and joins lines to produce output lines of (up to) the number of characters specified in the -w width option. The default width is 72. fmt concatenates the inputfiles listed as arguments. If none are given, fmt formats text from the standard input.
Blank lines are preserved in the output, as is the spacing between words. fmt does not fill nor split lines beginning with a `.' (dot), for compatibility with nroff(1). Nor does it fill or split a set of contiguous non-blank lines which is determined to be a mail header, the first line of which must begin with "From".
Indentation is preserved in the output, and input lines with differing indentation are not joined (unless -c is used).
fmt can also be used as an in-line text filter for vi(1). The vi command:
!}fmt
reformats the text between the cursor location and the end of the paragraph.
See environ(5) for a description of the LC_CTYPE environment variable that affects the execution of fmt.
See attributes(5) for descriptions of the following attributes:
Copyright © 1996-2007 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: March 15, 2008