簡單的格式化文本
fmt [option] [file-list]
?
fmt通過將所有非空白行的長度設置為幾乎相同,來進行簡單的文本格式化
?
參數
fmt從file-list中讀取文件,并將其內容的格式化版本發送到標準輸出。如果不制定文件名或者用連字符(-)來替代文件名,則fmt將從標準輸入讀取文本信息
?
選項
-s????????????? 截斷長行,但不合并
-t?????????????? 除每個段落的第1行外都縮進
-u????????????? 改變格式化,使字之間出現一個空格,句子之間出現兩個空格
-w n?????????? 將輸出的行寬改為n個字符。不帶該選項時,fmt輸出的行寬度為75個字符
?
示例
原文件
$ cat demo A long time ago, there was a huge apple tree. A little boy loved to come and play around it every day. He climbed to the tree top, ate the apples, took a nap under the shadow… He loved the tree and the tree loved to play with him.
?
fmt -s
$ fmt -s demo A long time ago, there was a huge apple tree. A little boy loved to come and play around it every day. He climbed to the tree top, ate the apples, took a nap under the shadow… He loved the tree and the tree loved to play with him.
截斷長行
?
fmt -t
$ fmt -t demo A long time ago, there was a huge apple tree. A little boy lovedto come and play around it every day. He climbed to the tree top,ate the apples, took a nap under the shadow… He loved the tree andthe tree loved to play with him.
排除首行的縮進
?
fmt -u
$ fmt -u demo A long time ago, there was a huge apple tree. A little boy loved to come and play around it every day. He climbed to the tree top, ate the apples, took a nap under the shadow… He loved the tree and the tree loved to play with him.
格式化單詞和句子的間隔,很明顯A little boy那里的多個空格被截斷到兩個
?
fmt -w
$ fmt -w 40 demo A long time ago, there was a huge apple tree. A little boy loved to come and play around it every day. He climbed to the tree top, ate the apples, took a nap under the shadow… He loved the tree and the tree loved to play with him.