ack: given multiple strings, print which one wasn't found

76 Views Asked by At

Given multiple strings to find with ack, is there a way/option/flag that will return the strings that were not found?

I.e., in this situation, I want "dog" to be output, as it's not found in the file

touch myFile.txt
echo 'hello, world' > data.txt 

ack "hello|world|dog"

However, "hello, world" is found

1

There are 1 best solutions below

0
gregory On

ack, like many search tools (grep, ag, ripgrep), only prints output from the source file (in this case, data.txt), not the pattern itself. Since the pattern 'dog' doesn't exist in the source file, it will not print regardless of the pattern you use.

You may be thinking of ack's flag --invert-match or grep's similar flag -v, but these flags only print content not matching the pattern. Again, since 'dog' is not in the file, it won't print: inverted flags do not print the pattern, but what content is searched for in the file.