亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 6152 | 回復(fù): 6
打印 上一主題 下一主題

comm, an easy and powerful command  關(guān)閉 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2005-12-15 23:24 |只看該作者 |倒序?yàn)g覽
In our work, we often encounter the following questions:

I have two files: file1 and file2:
1) How can I print out the lines that are only contained in file1?
2) How can I print out the lines that are only contained in file2?
3) How can I print out the lines that are contained both in file1 and file2?

There is a powerful shell command that can easily meet our needs, it is: comm. When you meet the above questions, "comm" should be your first choice

comm [ -123 ]  file1  file2

comm will read file1 and file2 and generate three columns of output: lines only in file1; lines only  in file2; and lines in both files. For detailed explanation, pls man comm.

Example:

bash-2.03$ cat file1
11111111
22222222
33333333
44444444
55555555
66666666
77777777
88888888
99999999
bash-2.03$ cat file2
00000000
22222222
44444444
66666666
88888888

1)  Print out the lines that are only contained in file1?
bash-2.03$ comm -23 file1 file2
11111111
33333333
55555555
77777777
99999999

2)  Print out the lines that are only contained in file2?
bash-2.03$ comm -13 file1 file2
00000000

3)  Print out the lines that are contained both in file1 and file2
bash-2.03$ comm -12 file1 file2
22222222
44444444
66666666
88888888

Besides the comm, we still have various ways to finish the above tasks.

1)  Print out the lines that are only contained in file1?
diff file1 file2 | grep "^<"|sed 's/^< //g'

for i in $(<file1); do (grep $i file2)||echo $i>>temp ; done;
      cat temp


In comparison, comm is much easier to remember.

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2005-12-16 09:51 |只看該作者
我的記憶是判斷那個(gè)文件沒(méi)有的,就把參數(shù)去掉。都有的才
file1中有file2中沒(méi)有 comm -23             #(file1有,把1去掉)
file1沒(méi)有有file2中有 comm -13             #(file2有,把2去掉)
file1和file2都存在   comm -12             #(都有,把3去掉)

論壇徽章:
1
榮譽(yù)會(huì)員
日期:2011-11-23 16:44:17
3 [報(bào)告]
發(fā)表于 2005-12-16 12:09 |只看該作者
使用comm需要注意的是下面的紅字
compare two sorted files line by line

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2005-12-16 13:19 |只看該作者
原帖由 寂寞烈火 于 2005-12-16 12:09 發(fā)表
使用comm需要注意的是下面的紅字
compare two sorted files line by line

Right!

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2005-12-16 13:43 |只看該作者
我習(xí)慣用win下的UltraEdit  沒(méi)排序的一樣比較   

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2005-12-16 13:47 |只看該作者
嘻,學(xué)習(xí)!

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2007-11-04 21:44 |只看該作者
thanks a lot
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專(zhuān)區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP