Ack for files with two phrases on Windows

1

I want to Ack for files that contain both "foo" AND "bar". I found lots of answers for how to do this on Linux, but not on Windows.

dake

Posted 2018-12-27T00:25:04.617

Reputation: 11

1Also why doesn't Ack offer an option to do this without any shell hacks? They offer so many seemingly useless flags. – dake – 2018-12-27T00:27:53.807

1ack is written in Perl5, so the documentation is the same. See https://beyondgrep.com/documentation/ . It's customary here for folks asking for help to provide samples of their scripts, and the resulting error messages, if the scripts fail. Please do so by clicking [edit] and expanding on your question, so everyone can see all the information about your issue. – K7AAY – 2018-12-27T00:36:27.373

Answers

1

The way you've probably seen is:

ack bar $(ack -l foo)

but that relies on shell specifics that I'm guessing Windows doesn't allow. Here's another way you can do it which should work in Windows.

ack -l foo | ack -x bar

The -x option says "use the file list from standard input as the list of files to search".

why doesn't Ack offer an option to do this without any shell hacks?

Because nobody's written it.

If you think it should be a feature, then the way to move that forward is by following the instructions in the manual:

   Please report any bugs or feature requests to the issues list at
   Github: https://github.com/beyondgrep/ack2/issues

They offer so many seemingly useless flags.

I suggest that what you are calling "useless flags" are "options that I have not figured out the use for yet".

Andy Lester

Posted 2018-12-27T00:25:04.617

Reputation: 1 121