linux下参数fmt,linux fmt命令

简单的格式化文本

fmt [option] [file-list]

fmt通过将所有非空白行的长度设置为几乎相同,来进行简单的文本格式化

参数

fmt从file-list中读取文件,并将其内容的格式化版本发送到标准输出。如果不制定文件名或者用连字符(-)来替代文件名,则fmt将从标准输入读取文本信息

选项

-s              截断长行,但不合并

-t               除每个段落的第1行外都缩进

-u              改变格式化,使字之间出现一个空格,句子之间出现两个空格

-w n           将输出的行宽改为n个字符。不带该选项时,fmt输出的行宽度为75个字符

示例

原文件

$ catdemo

Along time ago, there was a huge apple tree. A little boy loved to come and play around it every day. He climbed to the tree top, ate the apples, took a nap under the shadow… He loved the tree and the tree loved to play with him.

fmt -s

$ fmt -s demo

Along timeago, there was a huge apple tree. A little boy loved

to come and play around it every day. He climbed to the tree top, ate

the apples, took a nap under the shadow… He loved the tree and the

tree loved to play with him.

截断长行

fmt -t

$ fmt -t demo

Along timeago, there was a huge apple tree. A little boy loved

to come and play around it every day. He climbed to the tree top,

ate the apples, took a nap under the shadow… He loved the tree and

the tree loved to play with him.

排除首行的缩进

fmt -u

$ fmt -u demo

Along timeago, there was a huge apple tree. A little boy loved to come

and play around it every day. He climbed to the tree top, ate the apples,

took a nap under the shadow… He loved the tree and the tree loved to

play with him.

格式化单词和句子的间隔,很明显A little boy那里的多个空格被截断到两个

fmt -w

0818b9ca8b590ca3270a3433284dd417.png

$ fmt -w 40demo

Along timeago, there was a huge

apple tree. A little boy

loved to come and play around it

every day. He climbed to the tree top,

ate the apples, took a nap under the

shadow… He loved the tree and the

tree loved to play with him.

0818b9ca8b590ca3270a3433284dd417.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值