I'm searching for files based on a regular expression, and then I'm trying to search those files for content. So, for example, I have something like
#Find all C++ files that match a certain pattern and then search them find . -name "*.cpp" | grep "<name regex>" | xargs grep "<content regex>"
The problem I'm running into is that some of the paths have spaces in them, which confuses
xargs. I know that if I was just using
find, I could use the
-print0 argument (along with the
-0 argument on
xargs) to keep xargs from treating spaces as delimiters. Is there something similar with
Or am I approaching this problem in the wrong way entirely? Naively,
xargs grep makes sense to me, but I'm open to other approaches that yield the same results.