简单的格式化文本

fmt [option] [file-list]

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

参数

fmtfile-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

fmt命令的更多相关文章

  1. Go语言常用命令介绍

    go build go build 命令主要是用于测试编译.在包的编译过程中,若有必要,会同时编译与之相关联的包. 如果是普通包,当你执行go build命令后,不会产生任何文件. 如果是main包, ...

  2. 20个 Unix/Linux 命令技巧

    让我们用这些Unix/Linux命令技巧开启新的一年,提高在终端下的生产力.我已经找了很久了,现在就与你们分享. 删除一个大文件 我在生产服务器上有一个很大的200GB的日志文件需要删除.我的rm和l ...

  3. Linux常用脚本命令总结

    基本操作 通用操作 1. export 显示所有的环境变量,也可以获取到某个变量的详细信息: export # 显示所有 echo $SHELL # 只显示SHELL 2. whereis 使用系统自 ...

  4. 【Go命令教程】10. go fix 与 go tool fix

    命令 go fix 会把指定 代码包 的所有 Go 语言源码文件中的旧版本代码修正为新版本的代码.这里所说的版本即 Go 语言的版本.代码包的所有 Go 语言源码文件不包括其子代码包(如果有的话)中的 ...

  5. 【Go命令教程】6. go doc 与 godoc

    go doc 命令可以打印附于Go语言程序 实体 上的文档.我们可以通过把程序实体的标识符作为该命令的参数来达到查看其文档的目的. 插播:所谓 Go语言的 程序实体,是指变量.常量.函数.结构体以及接 ...

  6. Golang之go 命令用法

    Go 命令 Go 命令 Go语言自带有一套完整的命令操作工具,你可以通过在命令行中执行go来查看它们: 图1.3 Go命令显示详细的信息 这些命令对于我们平时编写的代码非常有用,接下来就让我们了解一些 ...

  7. Linux文本过滤常用命令(转)

    01 cat命令 通常用来显示文本文件的内容 一般用来查看比较短的文本文件,因为其缓冲区有限 -s选项可以用来合并文件中多余的空行,多个空行将被压缩为一个空行; -n选项可以显示行号 -b选项可以跳过 ...

  8. Go语言命令行操作命令详细介绍

    转自:http://www.jb51.net/article/56781.htm Go 命令 Go语言自带有一套完整的命令操作工具,你可以通过在命令行中执行go来查看它们: 图 Go命令显示详细的信息 ...

  9. GO的执行原理以及GO命令

    Go的执行原理以及Go的命令 一.Go的源码文件 Go 的源码文件分类: 如上图,分为三类: 1.命令源码文件: 声明自己属于 main 代码包.包含无参数声明和结果声明的 main 函数. 命令源码 ...

随机推荐

  1. Swift-Dictionary

    1.字典写法 Dictionary<KeyType,ValueType>,KeyType是你想要储存的键,ValueType是你想要储存的值. 唯一的限制就是KeyType必须是可哈希的, ...

  2. htaccess URL重写rewrite与重定向redirect(转)

    1. 将 .htm 页面映射到 .php 1 Options +FollowSymlinks 2 RewriteEngine on 3 RewriteRule ^(.*)\.htm$ $1.php [ ...

  3. 2015 UESTC Training for Search Algorithm & String - J - 全都是秋实大哥 【KMP】

    给出一个字符串,求每个前缀的最小循环节长度,并输出整个字符串的最小循环节.字符串长度为3*10^6 找循环节这种问题还是要用KMP对于长度为i的字符串 i%(i-f[i])==0 此时,它的最小循环节 ...

  4. MyBatis 学习总结(二)

    1.MyBatis基础环境的搭建 1.1 核心配置文件mybatis-config.xml <?xml version="1.0" encoding="UTF-8& ...

  5. 【开源java游戏框架libgdx专题】-11-核心库-演员类

    演员类,又称为Actor类,是libgdx开发中最基本的元素,可以被继承. 演员类,从OpenGL类的角度来理解,可以称为一个二维场景节点.它本身具有位置(postion).边界矩形(类似Retang ...

  6. PHP微信公众号 access_token缓存

    PHP创建access_token.json文件,将access_token 和 生成时间expires 保存在其中, {"access_token":"xxxx&quo ...

  7. Ajax数据格式,html,xml,json

    1. 2. 3. 4. 5. 6. 7. 8. 9.

  8. dbms_job dbms_scheduler简单比较

    ---------------------------陈旧的-------------------------------------/*--------------------- 创建job --- ...

  9. 苹果新政,禁止开发者在App中加入检查更新功能

    今天妥妥的被拒了,苹果更新了新政策,不能在应用中出现检测更新的功能.AppStore会自动提醒用户更新. 去掉更新按钮,之后再尝试下看能通过不能

  10. Xcode 的正确打开方式——Debugging(转)

    转自CocoaChina http://www.cocoachina.com/ios/20150225/11190.html 程序员日常开发中有大量时间都会花费在 debug 上,从事 iOS 开发不 ...