Multiple patterns with ack-grep?

2019-06-19 08:10发布

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

标签: regex grep ack
1条回答
我只想做你的唯一
2楼-- · 2019-06-19 08:35

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
查看更多
登录 后发表回答