← 返回列表

Linux shell fmt 命令

Linux shell fmt命令用于编排文本文件。 fmt 命令会从指定的文件里读取内容,将其依照指定格式重新编排后,输出到标准输出设备。 若指定的文件名为 -,则 fmt 会从标准输入设备读取数据。 fmt 命令语法格式 fmt [-cstu][-p<列起始字符串>][-w<每列字符数>][--help][--version][文件...] 参数 -c , --crown-margin 每段前两列缩排 -p<列起始字符串>,-prefix=<列起始字符串> 仅合并含有指定字符串的列,通常运用在程序语言的注解方面 -s或--split-only 只拆开字数超出每列字符数的列,但不合并字数不足每列字符数的列 -t或--tagged-paragraph 每列前两列缩排,但第1列和第2列的缩排格式不同 -u或--uniform-spacing 每个字符之间都以一个空格字符间隔,每个句子之间则两个空格字符分隔 -w<每列字符数> , --width=<每列字符数> , -<每列字符数> 设置每列的最大字符数 --help 在线帮助 --version 显示版本信息 范例 假设存在文件 demo1.txt,文件内容如下 [root@localhost ~/shell]# cat demo1.txt HELLO LINUX! Hello 简单教程 Linux is a free unix-type opterating system. This is a linux testfile! Linux test 我们使用 fmt 命令重排 demo1.txt 命令 [root@localhost ~/shell]# fmt demo1.txt HELLO LINUX! Hello 简单教程 Linux is a free unix-type opterating system. This is a linux testfile! Linux test 将 demo1.txt 重排成 30 个字符一行: [root@localhost ~/shell]# fmt -w 30 demo1.txt HELLO LINUX! Hello 简单教程 Linux is a free unix-type opterating system. This is a linux testfile!

Linux shell fmt命令用于编排文本文件。

fmt 命令会从指定的文件里读取内容,将其依照指定格式重新编排后,输出到标准输出设备。 若指定的文件名为 -,则 fmt 会从标准输入设备读取数据。

fmt 命令语法格式

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

参数

-c , --crown-margin 每段前两列缩排 -p<列起始字符串>,-prefix=<列起始字符串> 仅合并含有指定字符串的列,通常运用在程序语言的注解方面 -s或--split-only 只拆开字数超出每列字符数的列,但不合并字数不足每列字符数的列 -t或--tagged-paragraph 每列前两列缩排,但第1列和第2列的缩排格式不同 -u或--uniform-spacing 每个字符之间都以一个空格字符间隔,每个句子之间则两个空格字符分隔 -w<每列字符数> , --width=<每列字符数> , -<每列字符数> 设置每列的最大字符数 --help 在线帮助 --version 显示版本信息

范例

假设存在文件 demo1.txt,文件内容如下

[root@localhost ~/shell]# cat demo1.txt
HELLO LINUX!
Hello 简单教程
Linux is a free unix-type opterating system.
This is a linux testfile!
Linux test

我们使用 fmt 命令重排 demo1.txt 命令

[root@localhost ~/shell]# fmt demo1.txt
HELLO LINUX!  Hello 简单教程 Linux is a free unix-type opterating
system.  This is a linux testfile!  Linux test

将 demo1.txt 重排成 30 个字符一行:

[root@localhost ~/shell]# fmt -w 30 demo1.txt
HELLO LINUX!  Hello
简单教程 Linux is a free
unix-type opterating system.
This is a linux testfile!
Linux test

返回上一级

打开资源 ↗

交流与评论