Multiple patterns with ack-grep?

房东的猫 提交于 2019-12-10 13:34:35

问题


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".


回答1:


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


来源:https://stackoverflow.com/questions/6188879/multiple-patterns-with-ack-grep

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!