由于電源故障問題,我不得不清理基于文本檔案運行的作業。所以問題是,我有一個帶有這樣字串的文本檔案(它們是 uuid):
out_file.txt(約 300k 個條目)
<some_uuidX>
<some_uuidY>
<some_uuidZ>
...
和這樣的csv:
in_file.csv(約 500k 個條目)
/path/to/some/location1/,<some_uuidK>.json.<some_string1>
/path/to/some/location2/,<some_uuidJ>.json.<some_string2>
/path/to/some/location3/,<some_uuidX>.json.<some_string3>
/path/to/some/location4/,<some_uuidY>.json.<some_string4>
/path/to/some/location5/,<some_uuidN>.json.<some_string5>
/path/to/some/location6/,<some_uuidZ>.json.<some_string6>
...
我想從 out_file 中洗掉與 in_file 匹配的條目的行。最終結果:
/path/to/some/location1/,<some_uuidK>.json.<some_string1>
/path/to/some/location2/,<some_uuidJ>.json.<some_string2>
/path/to/some/location5/,<some_uuidN>.json.<some_string5>
...
由于檔案大小相當大,我想知道在 bash 中是否有一種有效的方法。
任何提示都會很好。
uj5u.com熱心網友回復:
這是一個潛在的grep解決方案:
grep -vFwf out_file.txt in_file.csv
還有一個潛在的awk解決方案(可能更快):
awk -F"[,.]" 'FNR==NR { a[$1]; next } !($2 in a)' out_file.txt in_file.csv
注意,每種方法都有一些警告。盡管它們似乎都適合您的預期目的(如您的評論“數字相加正確”所示),但在未來的問題中發布一個最小的、可重復的示例是幫助我們幫助您的最佳方式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/449195.html
標籤:重击
