Trying to identify the difference between the two methods.
I recently had to find a the string abcABC
in ~/path/
. In that same directory were the subdirectories ~/path/files/
and ~/path/docs/
along with a series of .h
, .cpp
and .txt
files. I only needed to look in the ~/path/
level so using:
grep -r -i abcABC ~/path/
produced findings in subdirectories which I didn't want.
Using the *
wildcard to extend the path to be ~/path/*.*/
allowed me to use:
grep -i abcABC ~/path/*.*
which found the subdirectories and files. However, I needed further refinement to only look at the .h
and .cpp
files for abcABC
.
Did some reading in man grep
and learned about --include=GLOB
and altered my command to the following:
grep -i --include \*.h --include \*.cpp abcABC ~/path/*.*
This worked, but then I tried (for S&G's) the following:
grep -i abcABC ~/path/*.{h,cpp}
and produced the same results I needed.
What I would like to know is what does { }
do for grep
? man grep
puts {n,m}
in repetition but I am not sure how doing this method equates to --include=GLOB
.
EDIT: Last response by Jordan gives great detailed Wikipedia example. The duplicate (slightly) problem provides great use case.