免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4705 | 回复: 9
打印 上一主题 下一主题

grep 逻辑与 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-09-21 10:01 |只看该作者 |倒序浏览
请问如何用grep实现逻辑与的查找功能?
比如
我想查找  *.xxx  中含有  description   和  value 两个单词的行
我试过
grep -e "description" -e "value" *.xxx  这是个逻辑或
到不到要求哈,
哪位知道, 说一下,谢了

论坛徽章:
1
天秤座
日期:2013-10-23 13:20:42
2 [报告]
发表于 2011-09-21 10:07 |只看该作者
grep -E "description|value"
or
egrep "description|value"

论坛徽章:
0
3 [报告]
发表于 2011-09-21 10:15 |只看该作者
no, you misunderstand me .
I got the answer in a foreign website
It is
grep -E "patten1.*pattem2" filename

And the answere you give me can implement OR fuction, which is not my want.

论坛徽章:
0
4 [报告]
发表于 2011-09-21 10:19 |只看该作者
for others, may it can help someone in the same trap

grep 'first pattern.*second pattern' foofile

This will not find lines where the 2nd pattern precedes the 1st one.

But this will:

egrep '1st pattern.*2nd pattern|2nd pattern.*1st pattern' foofile

论坛徽章:
0
5 [报告]
发表于 2011-09-21 10:47 |只看该作者
学习了!!!!!

论坛徽章:
1
天秤座
日期:2013-10-23 13:20:42
6 [报告]
发表于 2011-09-21 11:03 |只看该作者
you cant get my idea,so do by yourself.

论坛徽章:
0
7 [报告]
发表于 2011-09-21 11:35 |只看该作者
egrep '1st pattern.*2nd pattern|2nd pattern.*1st pattern' foofile

grep 1st pattern  file | grep 2nd pattern

jerryjzm写的是或  不是 与

论坛徽章:
1
天秤座
日期:2013-10-23 13:20:42
8 [报告]
发表于 2011-09-21 11:43 |只看该作者
sorry,题干都没看清就回答,审题不清
那这个简单,grep是支持正则表达式的

grep "description[空格].*[空格]value"

论坛徽章:
0
9 [报告]
发表于 2011-09-21 12:11 |只看该作者
学习

论坛徽章:
0
10 [报告]
发表于 2011-09-21 14:27 |只看该作者
法一、egrep 'description.*value|value.*description'  *.xxx

法二、grep description *.xxx|grep value
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP