Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple patterns with ack-grep?

Tags:

regex

grep

ack

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

like image 879
scrrr Avatar asked May 31 '11 14:05

scrrr


1 Answers

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
like image 168
Tim Pietzcker Avatar answered Oct 22 '22 16:10

Tim Pietzcker