【发布时间】:2020-09-24 08:39:09
【问题描述】:
我有一个大约 60000 行的 file1,一个大约 20000 行的 file2。我需要从 file1 中删除 file2 中存在的行。 File2 还包含 .* 以从 file1 中删除类似的模式。
文件1:
ABC DEG
bhdh jdjjd
cdhhd jdjd
ABC hjj
文件2:
ABC.*
cdhhd jdjd
输出应该是:
bhdh jdjjd
现在,我正在使用下面的代码。
while read -r line
do
sed -i "/${line}/d" $file1
done < "$file2"
使用此代码,大约需要 30 分钟才能获得输出。我真的需要一种更好的方法来从 file1 中删除这些行。
【问题讨论】:
-
类似于 grep 的答案,您可以使用
rg -vf file2 file1以获得更快的速度(rg 是 github.com/BurntSushi/ripgrep)...如果.*是您打算使用的正则表达式的范围,@从 file2 中删除.*后,987654328@ 和rg -vFf会更快
标签: linux performance shell unix grep