1 / 31

第九章

第九章. 簡易的過濾器. 查看檔案內容. more cat(concatenate) pg. pg, more. 在螢幕上每次顯示一頁 q    離開 pg filename more filename / pattern 向下尋求字串 n 向下尋求 q 離開 [enter] [space] 向下捲頁. wc. 計算行 , 字組及字元 The wc command counts lines, words, and bytes by default. l 計算行數 w 計算字組 words

jeb
Download Presentation

第九章

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第九章 簡易的過濾器

  2. 查看檔案內容 • more • cat(concatenate) • pg

  3. pg, more • 在螢幕上每次顯示一頁 • q   離開 • pg filename • more filename • / pattern向下尋求字串 • n 向下尋求 • q 離開 • [enter] [space] 向下捲頁

  4. wc • 計算行, 字組及字元 • The wc command counts lines, words, and bytes by default. • l 計算行數 • w 計算字組words • 不包含空白, 定位或換行字元 • m 計算character • c 計算字元byte • 包含空白, 定位或換行字元

  5. 計算標準輸出的行與字組 • ls |wc –l • who |wc –l • cat串接多個檔案 • cat out* | wc –w

  6. 用八進位顯示資料 • od • b 顯示每個字的八進位值 • c 顯示每個字 ls | od -bc 0000000 061 012 155 151 163 163 160 145 154 154 145 144 012 157 165 164 1 \n m i s s p e l l e d \n o u t 0000020 061 056 164 155 160 012 157 165 164 061 163 157 162 164 012 157 1 . t m p \n o u t 1 s o r t \n o 0000040 165 164 062 056 164 155 160 012 157 165 164 063 056 164 155 160 u t 2 . t m p \n o u t 3 . t m p

  7. cat • 適用於小檔案 • cat filename

  8. pr設定文字檔的頁數及表頭 • Write a file to a standard output • 多欄位輸出 • 轉換tab及空白字元 • 計算行數 • 簡單格式化

  9. pr設定文字檔的頁數及表頭 • pr –llen 設定每頁長度 pr -l15 verse • pr -h header 設定表頭 pr -h “UNIX CLASS” verse • pr -cols 多欄位輸出 pr -3 verse • pr +k 從第k行開始印出 • pr –t 移除頁首 • pr –d double space

  10. cmp 比較兩個檔案 • cmp –l group1 group2 47 62 61 第47個字元ASCII的八進位值為62,另一個為61 109 70 71 128 71 70

  11. cmp 比較兩個檔案 • 若兩個檔案相同,則不會顯示任何訊息 • 只會傳回簡單的提示符號 • 傳回true值 

  12. diff - 比較檔案內容 • >表來自第一檔案 • <表來自第二檔案 • diff file1 file2

  13. diff -f 由前向後修改 • diff -f file1 file2

  14. diff -c 最易讀 • context diff • ??表檔案二無此內容 • ?表檔案一無此內容 • 內容不同用?標示 • diff -c file1 file2

  15. comm什麼是相同的 • Compares two sorted files. • -1 Suppresses output of the first column (lines in file1 only). • -2 Suppresses output of the second column (lines in file2 only). • -3 Suppresses output of the third column (lines common to file1 and file2). • The command comm -123 produces no output.

  16. head • 印出檔案的頭部份 • head -n 顯示檔案的頭n行 • head -5 hammy

  17. tail • 印出檔案的尾部份 • default 10 • tail -n 印出檔案最後n行 • tail +n 跳到第n行然後將剩下的部份印出 • tail -r 以相反順序印出

  18. sort • 輸出到標準輸出 • 以ASCII排序 • 欄位0為第一欄 -c 檢查是否已排序過,若已排序不產生輸出 -d 依字典順序;忽略標點符號 -f 不理會大小寫 -k 指定排序欄位 -n 以算術順序排序 -M 依月份順序;Jan < Feb < Mar -r 反向排序 -t 使用分隔符號char來識別欄位(field) -u 輸出檔案中若有重複的行,只出現一次 -o 將輸出結果放到檔案中

  19. For instance, if fruits contains the text: banana orange Persimmon apple %%banana apple ORANGE then sort fruits displays: %%banana ORANGE Persimmon apple apple banana orange sort fruits

  20. sort -d -f -u fruit • The -u flag tells sort to remove duplicate lines, making each line of the file unique. This displays: apple %%banana orange Persimmon • Note that not only was the duplicate apple removed, but banana and ORANGE were removed as well. • The -d flag told sort to ignore symbols, so %%banana and banana were considered to be duplicate lines and banana was removed. • The -f flag told sort not to differentiate banana was removed. The -f flag told sort not to differentiate between uppercase and lowercase, so ORANGE and orange were considered to be duplicate lines and ORANGE was removed. • When the -u flag is used with input that contains nonidentical lines that are considered by sort (due to other flags) to be duplicates, there is no way to predict which lines sort will keep and which it will remove.

  21. If vegetables contains: yams:104 turnips:8 potatoes:15 carrots:104 green beans:32 radishes:5 lettuce:15 This sorts vegetables, comparing the text that follows the first colon on each line. The -t : option tells sort that colons separate fields. The -k 2 argument tells sort to ignore the first field and to compare from the start of the second field to the end of the line sort -t : -k 2 vegetables

  22. sort -t : -k 2 vegetables • then sort vegetables displays: carrots:104 yams:104 lettuce:15 potatoes:15 green beans:32 radishes:5 turnips:8

  23. sort -t : -k 2n -k 1r vegetables • This performs a numeric sort on the second field (-k 2n) and then, within that ordering, sorts the first field in reverse collating order (-k 1r). The output looks like this: radishes:5 turnips:8 potatoes:15 lettuce:15 green beans:32 yams:104 carrots:104 • The lines are sorted in numeric order; when two lines have the same number, they appear in reverse collating order.

  24. sort -o vegetables • To replace the original file with the sorted text, enter: sort -o vegetables vegetables • The -o vegetables flag stores the sorted output into the file veget ables.

  25. sort -t • 以|為分隔符號,加入\ 來取消其特殊意義,+1 排序第二個欄位 • sort –t \| +1 shortlist

  26. sort by key filed • +n以第n欄為key • sort +1 telnos gmk 245-3209 arm 333-3903 kc 362-4993

  27. names 0991M Christian, Kaare 0732M Raskin, Robin 0654C Smith, George 0220P Aldrige, Ricky 0739C Kitay, Ken 0184C Duffin, Pat

  28. sort by key filed • -n sort key到第n欄 • 第五個字元為sort key % sort +0.4 -0.5 names 0184C Duffin, Pat 0654C Smith, George 0739C Kitay, Ken 0732M Raskin, Robin 0991M Christian, Kaare 0220P Aldrige, Ricky

  29. sort -c • 檢查是否己排序 • sun4330% sort -c telnos sort: disorder: gmk 245-3209

  30. sort -n • 比較數字 • sort -n numbs 5 40 300 2000 10000

  31. sort-o outflie • Directs output to output_file instead of standard output. The output_file can be the same as one of the input files • 將結果存到檔案中 • sort telnos > telnos(錯誤) • sort telnos > telnos.tmp mv telnos.tmp telnos • sort -o telnos telnos

More Related