Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the fmt command of linux to orchestrate text files

Shulou Source: shulou.com Published: 2022-06-02 19:50:13 09月22日 Update

This article will show you how to format text files using linux's fmt command. There is a certain reference value, there are friends in need can refer to, I hope to help you.

The fmt command reads the contents from the specified file, reformats them according to the specified format, and outputs them to the standard output device. If the file name specified is "-," the fmt command reads data from a standard input device.

Syntax format: fmt [parameter] [file]

Common parameters:

-c Indent the first two columns of each paragraph-s Only break columns with more characters than each column, but do not merge columns with fewer characters-t Indent the first two columns of each column, but the indentation format for the first and second columns is different-u Each character is separated by a space character, and each sentence is separated by two space characters-w Sets the maximum number of characters per column

Reference Example

Rearrange specified files. If file has 5 lines of text, you can rearrange the file format by commanding:

[root@linuxcool ~]# fmt file

Rearrange file to 85 characters:

[root@linuxcool ~]# fmt -w 85 file

Have fmt highlight the first line:

[root@linuxcool ~]# fmt -t file

Split long rows with fmt:

[root@linuxcool ~]# fmt -s file

Space between words and sentences:

[root@linuxcool ~]# fmt -u file The above is a brief introduction to using the linux fmt command to arrange text files. Of course, the differences in using the above in detail must be understood by everyone themselves. If you want to know more, welcome to pay attention to the industry information channel!

Tags: File character command between format space reference text different line word parameter sentence word count standard device output maximum abbreviated two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Apple Docker vpn MySQL