zoukankan      html  css  js  c++  java
  • fmt命令

    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.htm
    https://www.runoob.com/linux/linux-comm-fmt.html
    https://www.geeksforgeeks.org/fmt-command-unixlinux/
    
  • 相关阅读:
    sync.waitGroup的wait可以多次wait,同时通知
    广播与服务(2)
    Android中的广播与服务(包含代码)
    Android的Activity的页面跳转和数据传递
    Android基础4(get、post乱码解决、Asynchttpclient的GET_POST访问网络、上传文件、多线程下载、多线程下载的Android移植、XUtils实现多线程下载)
    Android3的知识点补充
    Android基础3(数据库创建、增删改查、事务、listView)
    Android基础2(包含测试、保存数据、获取目录等)
    关于Android的基础概念
    c++与c几点比较
  • 原文地址:https://www.cnblogs.com/WindrunnerMax/p/14113272.html
Copyright © 2011-2022 走看看