Linux fmt command

Linux 命令大全Linux Command Reference

The Linux fmt command is used to format text files.

The fmt command reads content from specified files, reformats it according to the specified format, and 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<列起始字符串>][-w<每列字符数>][--help][--version][文件...]

Parameter description:

  • -c or --crown-margin Indent the first two lines of each paragraph.
  • -p<line-start string> or -prefix=<line-start string> Only merge lines containing the specified string, usually used for comments in programming languages.
  • -s or --split-only Only split lines that exceed the number of characters per line, but do not merge lines that are shorter than the character count per line.
  • -t or --tagged-paragraph Indent the first two lines of each paragraph, but the first and second lines have different indentation formats.
  • -u or --uniform-spacing Separate every character with one space character, and separate every sentence with two space characters.
  • -w<character count per line> or --width=<character count per line> or -<character count per line> Set the maximum number of characters per line.
  • --help Online help.
  • --version Display version information.

Examples

Reformat the specified file. For example, if the file testfile has 5 lines of text, you can reformat the file using the command. The command is:

fmt testfile 

The output result is as follows:

$ fmt testfile #重排testfile 文件  
hello Linux! Linux is a free Unix-type operating system. This is a  
Linux testfile! Linux Linux 

To reformat the file testfile into lines of 85 characters and output it on the standard output device, the command should be:

fmt -w 85 testfile

For comparison, first use the cat command to view the file content:

$ cat testfile #查看testfile 文件的内容  
hello Linux!  
Linux is a free Unix-type operating system.  
This is a Linux testfile!  
Linux  
Linux 

After reformatting with the fmt command, the output result is as follows:

$ fmt -w 85 testfile #指定重排宽度为85个字符  
hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile!  
Linux Linux 

Linux 命令大全Linux Command Reference

Other Extensions