我的檔案看起來像:file1:
8189157 7423700 7227471
8189199 7533538 7574425
8189200 7533538 7574425
8189273 7241932 7538338
8191298 6353935 6770138
8191332 7427024 7756709
8192601 6353935 7378544
8192680 7533538 7574348
8193100 6678109 7755961
8193158 6678109 7367734
8193159 6678109 7367734
8193176 7427024 7377679
8193180 7427024 7377679
8193227 6678109 7347206
8207305 7427024 7575134
8207315 6353935 7767680
8207316 6353935 7767680
8207317 6353935 7767680
8207371 6678109 7793130
8209083 7533538 7426859
8212702 7268724 7367752
8212704 7268724 7367752
8212718 7753798 7575212
8212719 7753798 7575212
我想從 file1 中提取與檔案 2 具有共同值的所有行:
7753798
6353935
7423700
所以結果應該是第三個檔案,如:
8212718 7753798 7575212
8212719 7753798 7575212
8207315 6353935 7767680
8207316 6353935 7767680
8207317 6353935 7767680
8191298 6353935 6770138
8192601 6353935 7378544
8189157 7423700 7227471
考慮到真正的file1很大的事實,請提出任何建議。
謝謝
uj5u.com熱心網友回復:
建議awk
腳本:
注意檔案順序很重要
awk '
FNR==NR{words[ cnt] = $0;next} # read search words from file2
{ # for each line in file1
for (i in words){ # scan each words
# if word is matched, print line and process next line
if ($0 ~ words[i]) {print; next}
}
}
' file2 file1
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/470210.html
上一篇:AIXKshgrep腳本問題