Linux系統中使用cmp和comm命令來比較兩個檔案

來源:互聯網
上載者:User

   cmp

  cmp 命令:比較任意兩個類型的檔案,且吧結果輸出到標準輸出,預設檔案相同不輸出,不同的檔案輸出差異

  必要參數

  -c 顯示不同的資訊

  -l 列出所有的不同資訊

  -s 錯誤資訊不提示

  選擇參數

  -i<字元數> 指定字元數目

  -v 顯示版本資訊

  --help 顯示協助資訊

  【函數的傳回值】

  0 :檔案時同樣的

  1 :檔案是不同的

  >1:發生錯誤

  例:

  代碼如下:

  [root@localhost www]# cmp test1.rb test.rb #比較二個檔案的不同

  test1.rb test.rb differ: byte 1, line 1

  [root@localhost www]# cmp -l test1.rb test.rb #顯示所有不同

  1 160 162

  2 165 145

  3 164 161

  4 163 165

  5 40 151

  6 42 162

  7 150 145

  8 145 40

  9 153 42

  10 153 155

  11 153 171

  12 42 163

  13 12 161

  cmp: EOF on test1.rb

  comm

  comm - 逐行比較兩個已排序的檔案

  逐行比較 已排序的 檔案 LEFT_FILE 和 RIGHT_FILE.

  -1

  屏蔽 左邊檔案 (LEFT_FILE) 中 不同於 右邊檔案 的 行(或內容)

  -2

  屏蔽 右邊檔案 (RIGHT_FILE) 中 不同於 左邊檔案 的 行(或內容)

  -3

  屏蔽 兩個檔案 中 相同 的 行(或內容)

  (譯註: 原文為 "不相同的行", 疑有誤)

  -l

  認為 輸入資料 根據 當前的 locale 排了序 (應該 給 sort 提供 -l 選項).

  --help

  顯示 協助資訊, 然後 結束

  --version

  顯示 版本資訊, 然後 結束

  例:

  代碼如下:

  [root@localhost www]# comm test.rb test1.rb #比較二個檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.