shell 段落注釋_shell,之重新格式化段落范文_第1頁
shell 段落注釋_shell,之重新格式化段落范文_第2頁
免費預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、shell 段落注釋_shell,之重新格式化段落-重新格式化段落 大部分功能強大的文本編輯器都提供重新格式化段落的命令;供用戶切分段落,使文本行數(shù)不要超出我們看到的屏幕范圍。這樣我們就引入了 fmt 命令,雖然一些 fmt 的實現(xiàn)有較多的選項可用,但其實只用:-s 僅切割較長的行,但不會將短行結(jié)合成較長的行,而 -w n 則設(shè)置輸出行寬度為 n 個字符 (默認通常是 75 個)。 fmt 命令的語法: fmt option file-list fmt 通過將所有非空白的長度設(shè)置為幾乎相同,來進行簡單的文本格式化。 -s 截斷長行,但不合并 -t 除每個段落的第 1 行外都縮進 -u 改變格式

2、化,使字之間出現(xiàn)一個空格,句子之間出現(xiàn)兩個空格 -w n 將輸出的行寬改為 n 個字符。不帶該選項時,fmt 輸出的行寬度為 75 個字符 例如,我有一個文件 demo,內(nèi)容為: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

3、to play with him.re使用命令 fmt -s 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, atethe apples, took a nap under the shadow he loved the tree and thetree loved to play with him.re該命令的含義是節(jié)段 2 長行。 使用 fmt -t demo 命令

4、的意思是說排除首行的縮進,結(jié)果為: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.re使用 fmt -u demo 命令的意思是說格式化單詞和句子的間隔。輸出為:a long time ag

5、o, there was a huge apple tree. a little boy loved to comeand 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 toplay with him.re顯然 a little boy 前面的多個空格變成了兩個。 使用命令 fmt -w 40 demo 意思是說指定行的寬度,這里的行寬為 40 個字符。所以輸出為:a lon

6、g time ago, there was a hugeapple tree. a little boyloved to come and play around itevery day. he climbed to the tree top,ate the apples, took a nap under theshadow he loved the tree and thetree loved to play with him.re僅作切割的選項: -s,在你想將長的行繞回,短的行保持不動時很好用,這么做也能使結(jié)果與原始版本間的差異達到最小,例如:fmt -s -w 10 eofone t

7、wo three four fivesixseveneight輸出為:one twothreefour fivesixseveneightrefmt 的小案例: 下面以拼音字典為例: 字典文件:/usr/dict/words 或者 /usr/share/dict/words。 sed -n -e 9991,10010p /usr/share/dict/words | fmt sed -n -e 9991,10010p /usr/share/dict/words | fmt -w 30 觀察上面兩行命令的輸出。 復(fù)習(xí)一下 sed 命令: sed 是一個很好的文件處理工具,本身是一個管道命令,主要

8、是以行為單位進行處理,可以將數(shù)據(jù)行進行替換、刪除、新增、選取等特定工作。假設(shè)我們有一個文件 demosed 1d demo 刪除第一行sed -n 1p 顯示第一行sed -n /root/p demo 查詢包括關(guān)鍵字 root 所在所有行sed 1a hahaha demo 第一行后增加字符串 hahahased 1,3a hahaha demo 第一行到第三行后增加字符串 hahahased 1c hihihi demo 第一行代替為 hihihised 1,2c hihihi demo 第一行和第二行替換為 hihihire替換一行中的某部分格式:sed s/ 要替換的字符串 / 新的字符串 /g ,案例:sed s/root/hahaha/g 替換 root 為 hahahased s/root/g 刪除 rootse

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論