fmt LINUX中的命令实际上是一个格式化程序,用于简化和优化文本文件。文本文件的格式化也可以手动完成,但对于大型文本文件来说,这可能非常耗时,这就是 fmt 来营救。
null
fmt 重新格式化指定文件中的每个段落,写入标准输出。下面是 fmt 命令:
// syntax of fmt command $fmt [-WIDTH] [OPTION]... [FILE]...
在哪里 -宽度 是公司的缩写 –宽度=位数 和 选项 指与应用程序兼容的选项 fmt 指挥与 文件 指的是文件名。
如果没有指定文件,或者文件是短划线(“-”), fmt 从标准输入读取。
使用fmt命令
fmt 默认情况下,如果不使用任何选项,请将给定文件中的所有单词格式化为一行。
$ cat kt.txt hello everyone. Have a nice day. /* fmt by default puts all words in a single line and prints on stdout. */ $fmt kt.txt hello everyone. Have a nice day.
要保存或写入格式化输出,您可以使用fmt作为:
/* Here the formatted output gets written in dv.txt */ $fmt kt.txt > dv.txt
fmt命令的选项
- -w、 –宽度=宽度选项: 默认情况下,fmt命令在输出中生成的最大宽度为75,但在 -w 选项可以更改,它只需要指定宽度的数值。
$cat kt.txt hello everyone. Have a nice day. /* the width gets reduced to 10 with -e option */ $fmt -w 10 kt.txt hello ever yone. Have a nice day.
- -t、 –标记段落选项: 可能需要突出显示文本文件中的第一行,这可以通过使第一行的缩进不同于其他行来完成 -t 命令。
$cat kt.txt hello everyone. Have a nice and prosperous day. /*-t makes the indentation of first line different from others */ $fmt -t kt.txt hello everyone. Have a nice and prosperous day.
- -s选项: 此选项可拆分长列,但不重新填充。
$cat kt.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. /* long lines get splited with -s option */ $fmt -s kt.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.
- -u、 –均匀间距选项: 此选项在单词之间使用一个空格,在句子之后使用两个空格进行格式化。
$cat kt.txt Love is patient, love is kind. It does not envy, it does not boast, it is not proud. /* Spaces are uniformed with -u option */ $fmt -u kt.txt Love is patient, love is kind. It does not envy, it does not boast, it is not proud.
- -c、 -皇冠保证金选项: 此选项保留前两行的缩进。
- -p、 –-prefix=字符串选项: 此选项将字符串作为参数,并仅重新格式化以字符串开头的行,将前缀重新附加到重新格式化的行。
- -g、 –目标=宽度选项: 此选项指的是目标宽度 即 默认宽度为93%。
- –帮助选项: 这将显示一条帮助消息并退出。
- -版本选项: 这将显示版本信息并退出。
fmt命令的应用:
- fmt 可以使用-u等选项轻松格式化大型文本文件,如果手动执行,这可能是一项非常困难的任务。
- fmt 还可以在-w选项的帮助下更改默认宽度。
- 在格式化文件时,这是一种节省时间的好方法。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END