博客
关于我
fmt命令
阅读量:405 次
发布时间:2019-03-06

本文共 1641 字,大约阅读时间需要 5 分钟。

fmt命令

fmt命令用于编排文本文件,其会从指定的文件里读取内容,将其依照指定格式重新编排后,输出到标准输出设备,若指定的文件名为-,则fmt指令会从标准输入设备读取数据。

语法

fmt [-WIDTH] [OPTION]... [FILE]...

参数

  • -c, --crown-margin: 保留前两行的缩进。
  • -p, --prefix=STRING: 仅重新格式化以STRING开头的行,并将前缀重新附加到格式化后的行上。
  • -s, --split-only: 拆分长行,但不再重新填充它们。
  • -t, --tagged-paragraph: 第一行的缩进不同于第二行。
  • -u, --uniform-spacing: 单词之间使用一个空格,句子后面使用两个空格。
  • -w, --width=WIDTH: 最大行宽(默认为75列)。
  • -g, --goal=WIDTH: 目标宽度(默认为宽度的93%)。
  • --help: 输出帮助信息。
  • --version: 输出版本信息。

示例

默认情况下,fmt不使用任何选项,将给定文件中存在的所有单词格式化为一行,当然默认单行最大宽度75

cat file.txt# Hello# everyone.# Have# a# nice # day.fmt file.txt# Hello everyone.  Have a nice day.

格式化文件,并使用-w选项指定文件行最大宽度,添加单词超出长度则将单词换行。

cat file.txt# Hello# everyone.# Have# a# nice # day.fmt -w 10 file.txt# Hello# everyone.# Have a# nice day.

-s选项分割了很长的行,但是不重新填充它们。

cat file.txt# Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It is not rude, it is not self-seeking, it is not easily angered,  it keeps no record of wrongs. Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres. Love never fails.fmt -s file.txt# Love is patient, love is kind. It does not envy, it does not boast, it# is not proud. It is not rude, it is not self-seeking, it is not easily# angered,  it keeps no record of wrongs. Love does not delight in evil# but rejoices with the truth. It always protects, always trusts, always# hopes, always perseveres. Love never fails.

每日一题

https://github.com/WindrunnerMax/EveryDay

参考

https://www.computerhope.com/unix/ufmt.htmhttps://www.runoob.com/linux/linux-comm-fmt.htmlhttps://www.geeksforgeeks.org/fmt-command-unixlinux/

转载地址:http://qockz.baihongyu.com/

你可能感兴趣的文章
mysql 索引
查看>>
MySQL 索引失效的 15 种场景!
查看>>
MySQL 索引深入解析及优化策略
查看>>
MySQL 索引的面试题总结
查看>>
mysql 索引类型以及创建
查看>>
MySQL 索引连环问题,你能答对几个?
查看>>
Mysql 索引问题集锦
查看>>
Mysql 纵表转换为横表
查看>>
mysql 编译安装 window篇
查看>>
mysql 网络目录_联机目录数据库
查看>>
MySQL 聚簇索引&&二级索引&&辅助索引
查看>>
Mysql 脏页 脏读 脏数据
查看>>
mysql 自增id和UUID做主键性能分析,及最优方案
查看>>
Mysql 自定义函数
查看>>
mysql 行转列 列转行
查看>>
Mysql 表分区
查看>>
mysql 表的操作
查看>>
mysql 视图,视图更新删除
查看>>
MySQL 触发器
查看>>
mysql 让所有IP访问数据库
查看>>