本文共 1504 字,大约阅读时间需要 5 分钟。
fmt命令用于对文本文件进行编排和格式化,能够根据指定的格式将内容重新排列并输出。若文件名为 "-",则fmt命令会从标准输入读取数据。
fmt命令的基本语法格式如下:
fmt [-WIDTH] [OPTION]... [FILE]...
以下是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/