我必须grep一个相当大的文本文件(~15 to )的3个不同的字符串。
即X+Y+Z+ .01% junk =完整文件
因此,有没有什么方法可以通过同时执行grep和grep -v函数来减少时间,因此逻辑流程应该是:
grep X filename.txt >> linescontainingstringX.
somehow do grep Y and grep Z on the remaining file ie grep Y >> linesnotcontainingstringX如果有适合我的方法,请告诉我。
发布于 2011-05-06 15:01:10
使用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/;'发布于 2011-05-06 13:32:16
使用egrep和匹配X、Y或Z的正则表达式。
http://www1.cs.columbia.edu/~tal/3261/fall07/handout/egrep_mini-tutorial.htm
egrep 'X|Y|Z` myFile.txt
https://stackoverflow.com/questions/5907138
复制相似问题