I would like to run grep
on Mac OS X that would meeting the following criteria:
- search all files with
*.R
or*.r
as extension and ignore other files - Find strings:
wordA
andwordB
accounting for the fact that the strings may appear in the formatsomeRubbishWordARubbish
(this is a valid match) - List only the files where both strings appear irrespectively of the order
- Print the lines where the strings appear
- Highlight the found words in colour
- Print the file name as a header and lines under the header. I'm inspired by the
ack
options. - Ignoring the case
Approach
I was thinking of making use of this discussion and starting with the following grep
syntax:
grep --include=*.R -r setHeader .
Then combining it with the following:
grep 'word1\|word2\|word3' /path
However, I would appreciate comments on ensuring that all of the criteria stated above will be evaluated correctly.
Groups
^(.*)(facet|map)(.*)(map|facet)(.*)$
Ack
Running ack -f
shows that *.R
files would be searched so solutions using ack
will be accepted. For example, running:
ack wordA --colour -i -H --rr
gets the desired results with respect to the wordA. I was thinking of combining it the solutions discussed here but I would like to use AND not OR and ignore the order in which strings may appear. I further tried:
ack --match wordA --match wordB --colour -i -H --rr
But this produced only the results for wordB
.