The fmt command reads the content from the specified file, reorchestrates it according to the specified format, and then outputs it to the standard output device. If the specified file name is "-", The fmt command reads data from the standard input device.
Syntax
Fmt [-cstu] [-p <column start string>] [-w <number of characters in each column>] [-- help] [-- version] [file...]
Parameter description:
- -C or -- crown-margin: scale down the first two columns of each segment.
- -P <column start string> or-prefix = <column start string> only merges columns containing the specified string, which is usually used in program language annotations.
- -S or -- split-only splits columns whose words exceed the number of characters in each column, but does not merge columns whose words are less than the number of characters in each column.
- -T or -- tagged-paragraph: the first two columns of each column are reduced, but the 1st and 2nd columns are in different formats.
- -U or -- uniform-spacing each character is separated by a space character, and each sentence is separated by two spaces.
- -W <number of characters in each column> or -- width = <number of characters in each column> or-<number of characters in each column> sets the maximum number of characters in each column.
- -- Help online help.
- -- Version: displays the version information.
Instance
Rearrange the specified file. For example, if the file testfile contains five lines of text, you can run the following command to rearrange the file format:
Fmt testfile
The output result is as follows:
$ Fmt testfile # rearrange the testfile
Hello Linux! Linux is a free Unix-type operating system. This is
Linux testfile! Linux
Repeat the file testfile into 85 characters and output it on the standard output device. The Command should be:
Fmt-w 85 testfile
For comparison, run the cat command to view the file content:
$ Cat testfile # view the content of the testfile file
Hello Linux!
Linux is a free Unix-type operating system.
This is a Linux testfile!
Linux
Linux
After fmt command is executed, the output result is as follows:
$ Fmt-w 85 testfile # specify 85 characters in the shuffling width
Hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile!
Linux