Linux 文档编辑 : fmt 命令详解

fmt命令读取文件的内容,根据选项的设置对文件格式进行简单的优化处理,并将结果送到标准输出设备。

语法

fmt(选项)(参数)

选项

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

参数

指定要优化格式的文件。

 

实例

重排指定文件。如文件testfile共5 行文字,可以通过命令对该文件格式进行重排,其命令为:

<span style="color:#000000">fmt testfile </span>

输出结果如下:

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

将文件testfile重新排成85 个字符一行,并在标准输出设备上输出,其命令应该为:

fmt -w 85 testfile-w 85 testfile

为了对比,先使用cat 命令查看文件内容:

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

使用fmt命令重排之后,输出结果如下:

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HarkerYX

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值