我需要一個Unix shell命令找到檔案1,不會出現線條可言file2中。例如 -
檔案 1:
aaa
bbb
檔案2:
aaaccc
bb
預期輸出:
bbb
(檔案 1 中的“aaa”確實出現在檔案 2 中,作為較大字串“aaaccc”的一部分)。
我不能使用“comm”,因為它只適用于完整的行。在這種情況下,我還希望排除 file2 中包含 file1 中的行作為較大字串的一部分的行,如上所述。
請注意,如果存在,我更喜歡快速方法,因為我的檔案非常大。
uj5u.com熱心網友回復:
awk 中的一個,mawk 可能是最快的,所以使用那個:
$ awk '
NR==FNR { # process file1
a[$0] # hash all records to memory
next # process next record
}
{ # process file2
for(i in a) # for each file1 entry in memory
if($0 ~ i) # see if it is found in current file2 record
delete a[i] # and delete if found
}
END { # in the end
for(i in a) # all left from file1
print i # are outputted
}' file1 file2 # mind the order
輸出:
bbb
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/368554.html
