comm指令
對已經有序的檔案進行比較
第一列隻在檔案1中出現的檔案,第二列隻在檔案2中出現的檔案,第三列在檔案1和檔案2中同僚出現的檔案
comm對檔案進行處理時,要求檔案已經有序,如果沒有順序,請使用sort進行排序後進行處理。
語 法:
comm [-123][--help][--version][第1個檔案][第2個檔案]
補充說明:
這項指令會一列列地比較兩個已排序檔案的差異,并将其結果顯示出來,如果沒有指定任何參數,則會把結果分成3行顯示:
第1行僅是在第1個 檔案中出現過的列;
第2行是僅在第2個檔案中出現過的列;
第3行則是在第1與第2個檔案裡都出現過的列。
若給予的檔案名稱為"-",則comm指令會從标 準輸入裝置讀取資料。
參 數:
-1 不顯示隻在第1個檔案裡出現過的列。
-2 不顯示隻在第2個檔案裡出現過的列。
-3 不顯示同時在第1和第2個檔案裡出現過的列。
--help 線上幫助。
--version 顯示版本資訊
debian:/shell# cat a1
1
2
3
4
5
6
debian:/shell# cat a2
7
8
debian:/shell# comm a1 a2
1
2
3
4
7
8
debian:/shell# comm -1 a1 a2
1
2
3
4
debian:/shell# comm -2 a1 a2
1
2
3
4
debian:/shell# comm -3 a1 a2
7
8
debian:/shell# comm -13 a1 a2
debian:/shell# comm -23 a1 a2
debian:/shell#
希望我不會遺忘!
debian:/shell# egrep -f a1 a2
debian:/shell# egrep -f a1 -v a2
debian:/shell# egrep -f a2 -v a1
本文轉自crazy_charles 51CTO部落格,原文連結:http://blog.51cto.com/douya/1651246,如需轉載請自行聯系原作者