ack-grep有多种模式? [英] Multiple patterns with ack-grep?

查看:101
本文介绍了ack-grep有多种模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能(以及如何)将模式与ack链接起来(在Linux的某些发行版上使用ack-grep),就像我习惯于使用grep一样?

例如

  grepfoosomefile.c | grep -vbar

...将所有行与foo匹配但没有bar 。

解决方案> ack 使用Perl正则表达式, a href =http://www.regular-expressions.info/lookaround.html =noreferrer>前瞻断言:

  ^(!!。bar)。* foo。* 

将与包含 foo 但不包含 bar 的行匹配。



我不熟悉 ack 的用法,但是应该这样做:

  ack'^(?!。* bar)。* foo。* $'myfile 


Is it possible (and how) to chain patterns with ack (ack-grep on some distributions of Linux) like I'm used to with grep?

e.g.

grep "foo" somefile.c | grep -v "bar"

...to match all lines with "foo" but without "bar".

解决方案

ack uses Perl regular expressions, and those allow lookahead assertions:

^(?!.*bar).*foo.*$

will match a line that contains foo but doesn't contain bar.

I'm not familiar with the usage of ack, but something like this should work:

ack '^(?!.*bar).*foo.*$' myfile

这篇关于ack-grep有多种模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆