This tutorial explains Linux “fmt” command, options and its usage with examples.
DESCRIPTION
fmt is a formatter for simplifying and optimizing text files.
SYNOPSIS
fmt [-c] [-s] [-w width | -width ] [inputfile]
OPTIONS
-c
Crown margin mode. Preserve the indentation of the first two lines within a paragraph, and align the left margin of each subsequent line with that of the second line. This is useful for tagged paragraphs.
-s
Split lines only. Do not join short lines to form longer ones. This prevents sample lines of code, and other such formatted text, from being unduly combined.
-w width | -width
Fill output lines to up to width columns.
inputfile
The input file.
EXAMPLES
1. Given the contents of file file1.txt, fmt works as follows
$ cat file1.txt abc def ghi $ fmt file1.txt abc def ghi
Simply using fmt formats text in a single line.
2. Let abc file contains some text, then giving a width of 1 produces output
$ cat abc 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 -w 1 abc 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.
3. Crown Margin Mode
This example shows the crown margin usage.
$ cat abc 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 -c abc 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.
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.
- Practice Programming MCQs
- Check Linux Books
- Apply for Programming Internship
- Check Information Technology Books