fmt命令
命令 fmt
2023-09-11 14:21:33 时间
简单的格式化文本
fmt [option] [file-list]
fmt通过将所有非空白行的长度设置为几乎相同,来进行简单的文本格式化
参数
fmt从file-list中读取文件,并将其内容的格式化版本发送到标准输出。如果不制定文件名或者用连字符(-)来替代文件名,则fmt将从标准输入读取文本信息
选项
-s 截断长行,但不合并
-t 除每个段落的第1行外都缩进
-u 改变格式化,使字之间出现一个空格,句子之间出现两个空格
-w n 将输出的行宽改为n个字符。不带该选项时,fmt输出的行宽度为75个字符
示例
原文件
$ cat demo
A long 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
A long 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 -t
$ fmt -t demo
A long 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 -u
$ fmt -u demo
A long 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.
格式化单词和句子的间隔,很明显A little boy那里的多个空格被截断到两个
fmt -w
$ fmt -w 40 demo
A long 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.
指定输出的行宽,这里的行宽为40个字符,我没数过
reference:http://www.cnblogs.com/nerxious/archive/2013/01/09/2853091.html
相关文章
- Linux系统下安装rz/sz命令及使用说明
- SVN基础命令使用
- linux使用tar命令打包压缩时排除某个文件夹或文件
- Linux chmod命令详解
- Linux pgrep命令查找正在运行的进程ID
- Linux poweroff关机命令
- linux ps查看进程命令
- Python Django根据数据库表生成模型类的命令
- [Shell] 字符截取命令:cut, printf, awk, sed
- Atititt java redis jedis 使用 Redis体系 Redis 命令 Redis 命令Redis 键(key)Redis 字符串(String)Redis 哈希(Hash)R
- vim 实用命令记录 (自用)
- linux基本功系列-which命令实战
- Linux命令之rz - 批量上传文件,简单易用(转载)
- 测试常用的Linux、adb、Monkey命令
- redis的set命令学习
- 批处理命令——choice
- Linux常用命令——grep命令和通配符以及