Sal
Sal

Reputation: 3269

Executing grep on multiple find results

My question is rather similar to this one, except that I'm executing a grep search on multiple find queries. (I have to do this because I have to submit my command to the live servers, and I'd like to tinker with them as little as possible.)

Here is my query:

find /c/some/dir/ -iname "*html" -o -iname "*tpl" -exec grep -inH 'search_string' {} \;

With the -o option, the grep search returns all of the instances of "search_string" in the files that end with tpl. It completely ignores the html extensions I passed in...

Has anyone encountered this? How do I tell find to execute the grep on both html and tpl extensions?

(I'm running Cygwin, which has had some Windows translation issues in the past, so that may be a culprit...)

Upvotes: 0

Views: 189

Answers (1)

twalberg
twalberg

Reputation: 62379

I think you need to group the two -iname clauses, like this:

find /c/some/dir/ \( -iname "*html" -o -iname "*tpl" \) -exec grep -inH 'search_string' {} \;

The logical or has a lower precedence, which means the -exec bits only apply to your -iname "*tpl" clause.

Upvotes: 2

Related Questions