作者jacobcan118 (jacobcan118)
看板LinuxDev
標題[問題]比較兩個檔案特定欄位
時間Tue Nov 10 10:59:02 2015
請問各位在unix有什麼比較好的方法用shell script可以比較兩個檔案中第其中一欄位的值.兩個檔案會
1:每行所含的資料順序不一定一樣,有資料在檔案A出現在檔案B不一定出現
2:想比較第三欄(yes, no,empty)的值
如
File A:
$cat A.log
case1,0.0001,yes
case2,0.0021,no
case3,0.0041,no
case4,0.0041,empty
case5,0.0101,empty
case6,0.0501,yes
File B:
$cat A.log
case1,0.0001,yes
case7,0.0021,yes
case2,0.0041,yes
case3,0.0041,empty
希望output:
case2 no yes:case3 no empty:case4 empty " ":case5 empty " ":case6 yes " ":case7 " " yes.
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 72.80.104.128
※ 文章網址: https://www.ptt.cc/bbs/LinuxDev/M.1447124344.A.D81.html
→ redshoe: sed,sort ,diff,awk,pipe ? 11/11 11:10
→ kerwinhui: 先sort再用join的-o 11/11 12:44
→ jacobcan118: 感謝 sort + join有用 11/12 12:22