I need a way to run grep on a list of files which may contain spaces in the file name. On a list of files with no spaces, it's pretty straight forward and easy. Also, I know how to deal with spaces in the file names for find and xargs. I'm just looking for a way to use grep
with the -print0 command.
I'm looking for text inside the file, not in the filename...
This lists all files:
find * -print 0 | xargs -0 -i{} echo {}
but say I have to do a grep (or some other command) inbetween.
This lists files which contain "howdy doody" inside the file:
find * | xargs grep -l "howdy doody" | xargs -i{} echo {}
This doesn't work, grep
doesn't know how to recognize null terminated lines. Did I miss something in grep
's man page?
find * -print0 | xargs grep -l "howdy doody" | xargs -0 -i{} echo {}