fmt命令-格式化文字

时间:2019-04-29 03:17:28  来源:igfitidea点击:

使用fmt格式化文本文件

fmt命令可用于快速格式化文本并将其转换为其他宽度。默认情况下,fmt命令将创建宽度为75个字符的文本。fmt也可以通过-u或--uniform-spacing选项将均匀的间距应用于文件。

以下是正在使用的fmt命令的一些简单示例。

test.txt:

john@ls001a:~> cat test.txt

The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.

不带选项的fmt

john@ls001a:~> fmt test.txt
The quick brown fox jumps over the lazy dog.  The quick brown fox
jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.  The quick brown fox
jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.  The quick brown fox
jumps over the lazy dog.  The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.

在上面的示例中,这些行的连接宽度最大为75个字符。

使用fmt命令时指定宽度

john@ls001a:~> fmt --width=20 test.txt
The quick brown fox
jumps over the lazy
dog.  The quick
brown fox jumps
over the lazy dog.
The quick brown fox
jumps over the lazy
dog.  The quick
brown fox jumps
over the lazy dog.
The quick brown fox
jumps over the lazy
dog.  The quick
brown fox jumps
over the lazy dog.
The quick brown fox
jumps over the lazy
dog.  The quick
brown fox jumps
over the lazy dog.
The quick brown fox
jumps over the lazy
dog.  The quick
brown fox jumps
over the lazy dog.

在此示例中,我们将宽度设置为20个字符。