简明Linux命令行笔记:fmt
来源:互联网 发布:最近网络流行的词语 编辑:程序博客网 时间:2024/06/05 08:15
简单的格式化文本
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 lovedto come and play around it every day. He climbed to the tree top, atethe apples, took a nap under the shadow… He loved the tree and thetree 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 comeand 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 toplay with him.
格式化单词和句子的间隔,很明显A little boy那里的多个空格被截断到两个
fmt -w
$ fmt -w 40 demo A long time ago, there was a hugeapple tree. A little boyloved to come and play around itevery day. He climbed to the tree top,ate the apples, took a nap under theshadow… He loved the tree and thetree loved to play with him.
指定输出的行宽,这里的行宽为40个字符,我没数过
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 简明Linux命令行笔记:fmt
- 简明Linux命令行笔记:ls
- 简明Linux命令行笔记:gzip
- 简明Linux命令行笔记:whereis
- 简明Linux命令行笔记:locate
- 简明Linux命令行笔记:umask
- 简明Linux命令行笔记:chgrp
- 简明Linux命令行笔记:chmod
- 简明Linux命令行笔记:tr
- 简明Linux命令行笔记:uniq
- 简明Linux命令行笔记:wc
- 简明Linux命令行笔记:comm
- 简明Linux命令行笔记:cut
- 简明Linux命令行笔记:tee
- 简明Linux命令行笔记:dmesg
- 简明Linux命令行笔记:hwclock
- 简明Linux命令行笔记:rm
- 简明Linux命令行笔记:bzip2
- 简明Linux命令行笔记:tr
- 简明Linux命令行笔记:uniq
- 简明Linux命令行笔记:wc
- Meta programming 学习 <二> Template parameter
- linux net_bridge结构简介
- 简明Linux命令行笔记:fmt
- 《Windows网络与通信程序设计》读书笔记----可伸缩服务器系统设计实例
- 不需要显式地声明tld路径了
- ubuntu下emacs的配置(cedit,ecb)
- 在一台Windows电脑上安装多个Mysql服务的方法
- 简明Linux命令行笔记:comm
- 链表的基本操作
- Linux驱动中的异步通知
- 简明Linux命令行笔记:cut