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

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

fmt命令

fmt命令用于对文本文件进行编排和格式化,能够根据指定的格式将内容重新排列并输出。若文件名为 "-",则fmt命令会从标准输入读取数据。

语法

fmt命令的基本语法格式如下:

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

参数说明

以下是fmt命令的主要参数:

  • -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命令的版本信息。

示例

  • 默认格式化

    fmt命令不使用任何选项,将文件中的所有单词格式化为一行,行宽默认为75列。

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

    格化后的输出:

    Hello everyone. Have a nice day.
  • 指定行宽

    使用 -w选项指定行宽为10列,超出单词长度的部分会换行。

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

    格化后的输出:

    Helloeveryone.Haveaniceday.
  • 仅拆分长行

    使用 -s选项将长行拆分为多行,但不进行重新填充。

    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.

    格化后的输出:

    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.
  • 参考资料

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

    你可能感兴趣的文章
    Objective-C实现CaesarsCiphe凯撒密码算法(附完整源码)
    查看>>
    Objective-C实现calloc函数功能(附完整源码)
    查看>>
    Objective-C实现canny边缘检测算法(附完整源码)
    查看>>
    Objective-C实现cartesianProduct笛卡尔乘积算法(附完整源码)
    查看>>
    Objective-C实现check strong password检查密码强度算法(附完整源码)
    查看>>
    Objective-C实现chudnovsky algorithm楚德诺夫斯基算法(附完整源码)
    查看>>
    Objective-C实现CIC滤波器(附完整源码)
    查看>>
    Objective-C实现circle sort圆形排序算法(附完整源码)
    查看>>
    Objective-C实现CircularQueue循环队列算法(附完整源码)
    查看>>
    Objective-C实现clearBit清除位算法(附完整源码)
    查看>>
    Objective-C实现climbStairs爬楼梯问题算法(附完整源码)
    查看>>
    Objective-C实现cocktail shaker sort鸡尾酒排序算法(附完整源码)
    查看>>
    Objective-C实现cocktailShakerSort鸡尾酒排序算法(附完整源码)
    查看>>
    Objective-C实现CoinChange硬币兑换问题算法(附完整源码)
    查看>>
    Objective-C实现collatz sequence考拉兹序列算法(附完整源码)
    查看>>
    Objective-C实现Collatz 序列算法(附完整源码)
    查看>>
    Objective-C实现comb sort梳状排序算法(附完整源码)
    查看>>
    Objective-C实现combinationSum组合和算法(附完整源码)
    查看>>
    Objective-C实现combinations排列组合算法(附完整源码)
    查看>>
    Objective-C实现combine With Repetitions结合重复算法(附完整源码)
    查看>>