首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >grep和grep -v同时执行

grep和grep -v同时执行
EN

Stack Overflow用户
提问于 2011-05-06 13:28:21
回答 2查看 764关注 0票数 0

我必须grep一个相当大的文本文件(~15 to )的3个不同的字符串。

即X+Y+Z+ .01% junk =完整文件

因此,有没有什么方法可以通过同时执行grep和grep -v函数来减少时间,因此逻辑流程应该是:

代码语言:javascript
复制
grep X filename.txt >> linescontainingstringX.
somehow do grep Y and grep Z on the remaining file ie grep Y >> linesnotcontainingstringX

如果有适合我的方法,请告诉我。

EN

回答 2

Stack Overflow用户

发布于 2011-05-06 15:01:10

使用perl。

代码语言:javascript
复制
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/;'
票数 2
EN

Stack Overflow用户

发布于 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5907138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档