0

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...)

Community
  • 1
  • 1
Sal
  • 3,179
  • 7
  • 31
  • 41

1 Answers1

2

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.

twalberg
  • 59,951
  • 11
  • 89
  • 84
  • This is what I thought, but I didn't know how the statements were parsed. I'll try this now and accept the answer if appropriate. Thanks! – Sal Mar 25 '13 at 20:13