Linux fmt命令詳解 Linux fmt命令怎麼用

來源:互聯網
上載者:User

fmt指令會從指定的檔案裡讀取內容,將其依照指定格式重新編排後,輸出到標準輸出裝置。若指定的檔案名稱為"-",則fmt指令會從標準輸入裝置讀取資料。

文法

fmt [-cstu][-p<列起始字串>][-w<每列字元數>][--help][--version][檔案...]

參數說明:

  • -c或--crown-margin 每段前兩列縮排。
  • -p<列起始字串>或-prefix=<列起始字串> 僅合并含有指定字串的列,通常運用在程式語言的註解方面。
  • -s或--split-only 只拆開字數超出每列字元數的列,但不合并字數不足每列字元數的列。
  • -t或--tagged-paragraph 每列前兩列縮排,但第1列和第2列的縮排格式不同。
  • -u或--uniform-spacing 每個字元之間都以一個空白字元間隔,每個句子之間則兩個空白字元分隔。
  • -w<每列字元數>或--width=<每列字元數>或-<每列字元數> 設定每列的最大字元數。
  • --help 線上協助。
  • --version 顯示版本資訊。

執行個體

重排指定檔案。如檔案testfile共5 行文字,可以通過命令對該檔案格式進行重排,其命令為:

fmt testfile

輸出結果如下:

$ fmt testfile #重排testfile 檔案

hello Linux! Linux is a free Unix-type operating system. This is a

Linux testfile! Linux Linux

將檔案testfile重新排成85 個字元一行,並在標準輸出裝置上輸出,其命令應該為:

fmt -w 85 testfile

為了對比,先使用cat 命令查看檔案內容:

$ cat testfile #查看testfile 檔案的內容

hello Linux!

Linux is a free Unix-type operating system.

This is a Linux testfile!

Linux

Linux

使用fmt命令重排之後,輸出結果如下:

$ fmt -w 85 testfile #指定重排寬度為85個字元

hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile!

Linux Linux

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.