1

I have installed strawberry-perl on my windows 7 laptop.

I want to search for a list of words using grep or ack on windows. I have been able to perform basic searches using ack, but I just don't know how to pass a list of words to ack So I want to pass a list of words to ack and find out the line numbers where these words occur. Both words do not have to occur on the same line.

For example, if I am searching for "doll" and "house", I could have doll on line 12 and house on line 244.

I tried something like this ack "doll"|"house" but it throws the following error.

Expressions are only allowed as the first element of a pipeline.
At line:1 char:22
+ ack "doll" | "house" <<<<
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline
abhi
  • 3,082
  • 6
  • 47
  • 73

1 Answers1

1

So you're saying you want to find all the files where "doll" appears and where "house" appears. So here's what you do.

First, find all the files that contain "doll", and print a list of them.

ack -l doll

Then search that list of files for the word "house".

ack house $(ack -l doll)

Or, if you're not running a shell that lets you do that (i.e. Windows), you can do:

ack -l doll | ack -x house

ack -x says "Take the list of files to search from STDIN".

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
  • 1
    Thank you for taking the time to reply. Hopefully I still have this setup on the desktop. – abhi Apr 16 '14 at 13:23