我必须为 3 个不同的字符串搜索一个非常大的文本文件 (~15GB)。需要注意的重要一点是 X、Y 和 Z 这三个字符串占文本文件的大约 99.9%,并且互斥。
即 X + Y + Z + .01% 垃圾 = 完整文件
那么有什么方法可以通过同时执行 grep 和 grep -v 函数来减少时间 因此逻辑流程应该是:
grep X filename.txt >> linescontainingstringX.
somehow do grep Y and grep Z on the remaining file ie grep Y >> linesnotcontainingstringX
如果有适合我的方法,请告诉我。
最佳答案
使用 perl。
perl -n -e 'BEGIN{ open XFILE,">x.txt" or die "$!" ; open YFILE,">y.txt" or die "$!"; open ZFILE, ">z.txt" or die "$!";} print XFILE $_ if /X/; print YFILE $_ if /Y/; print ZFILE $_ if /Z/;'
关于linux - grep 和 grep -v 同时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5907138/