I'm trying to search for lines containing 'foo' but these lines must not contain 'bar'. What's a good way to search with these parameters with ack
?
I can do:
ack "foo" | grep -v "bar"
but it doesn't keep the nicely layed-out and coloured output of ack
. Also, grep
doesn't have good support for Perl regexes, unlike ack
.
awk
? It will do this with ease. – Colenecoleopteranack
is more suited for searching text files, particularly source code, and has a lot of features suited for this that make it a better tool for such tasks thanawk
. e.g.awk
only supports POSIX ERE which is kind of a deal-breaker for me; on the other hand,ack
supports Perl regex. – Suckawk
without using regex. If your system does haveawk
try it out usingtime
to see what is fastest like thistime awk '/foo/ && !/bar/' file
Then you can make a selection based onportability
easy to understand
andspeed
– Colenecoleopteran