Latest web development tutorials

Linux fmt command

Linux command Daquan Linux command Daquan

Linux fmt command is used to format text files.

fmt command reads the content from the specified file after it is rearranged in accordance with the specified format, to the standard output device. If the specified file name is "-", the fmt command will read data from the standard input device.

grammar

fmt [-cstu][-p<列起始字符串>][-w<每列字符数>][--help][--version][文件...]

Parameter Description:

  • -c or --crown-margin indent each front two.
  • -p <column starting string> or -prefix = <string starting column> column fractions containing only the specified string, usually used in the annotations procedural language.
  • -s or --split-only just exceeded the number of words apart each column character columns, but not less than the number of words per column combined number of characters in the column.
  • -t --tagged-paragraph or two before each column indent, but the difference between the first one and the indention of the first two.
  • -u Or --uniform-spacing between each character with a space character interval, the two separated by a space character between each sentence.
  • -w <number of characters per column> or --width = <number of characters per row> or - <number of characters per row> Sets the maximum number of characters per column.
  • --help online help.
  • --version display version information.

Examples

Rearrangement of the specified file. Such as file testfile 5 lines of text, you can rearrange the file format of the command, its command:

fmt testfile 

The output is as follows:

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

The file testfile re-arranged line of 85 characters, and output on the standard output device, the command would be:

fmt -w 85 testfile

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

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

After using the fmt command rearrangement, the output results are 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 command Daquan Linux command Daquan