7

How do you use ack to search for a file that contains, for example,

  1. cat
  2. dog
  3. mouse

anywhere in the file? Each phrase occur at least once in the file.

This is kind of like the behavior of an online search engine.

Bonus:

  1. Can we use regex on those individual phrase as well?
  2. Or perhaps declare at least how many times a phrase must occur?

2 Answers 2

6

@kirkbauer suggested

ack phrase2 `ack -l phrase1`

and that will indeed work. I prefer to use the $() syntax instead of ``` ` syntax

ack phrase2 $(ack -l phrase1)

With the release of ack 2.0, you get the -x switch so that you can do this:

ack -l phrase1 | ack -x phrase2

The -x tells ack to take the list of files to read from STDIN.

6

This should do the trick: perform first ack, get file list, look for second set of files.

ack phrase2 `ack -l phrase1`

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .