0

I had a bit of trouble with find. This didn't do what I expected:

find . -iname "*.hh" -or -iname "*.h" -exec grep -inH "IDENTIFIER" {} \; 

I expected it to grep in both *.hh and *.h files but it only greps the result of -iname "*.h". I resorted to using xargs to solve it.

find . -iname "*.hh" -or -iname "*.h" | xargs grep -inH "IDENTIFIER" 

But is there a way to use -exec without writing it twice like this:

find . -iname "*.hh" -exec grep -inH "IDENTIFIER" {} \; -or -iname "*.h" -exec grep -inH "IDENTIFIER" {} \; 

2 Answers 2

3

You can say:

find . \( -iname "*.hh" -o -iname "*.h" \) -exec ... 

to find both *.hh and *.h files.

Sign up to request clarification or add additional context in comments.

Comments

1

You could also do it with the regex option to grep:

find . -regex '.*\.hh?' -exec grep -inH "IDENTIFIER" {} \;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.