I'm trying to search a lot of .xml files for certain strings but not other strings and I'm having trouble putting a command together to do it. I only want it to list the file names that match the inclusion/exclusion criteria. I've been trying:
find . -name *.xml -exec grep -li "string1\|string2" {} \; | xargs grep -Li "string3\|string4"
But I'm having trouble because the file names that are returned from the find have spaces in their names and the second grep breaks them all into little chunks and of course doesn't find such files. I've tried adding -0 to the xargs and it removes the errors but it says "File name too long" and only executes the first grep.
Please let me know how to tweak this command to have it work properly on files with spaces in the names.
Thanks in advance
find . -name "*.xml" -exec grep -liZ "string1\|string2" {} \; | xargs -0 grep -Li "string3\|string4"(TheZflag togrepoutputs zero terminators on its results list, which should be compatible withxargs -0) – Matt Gibson Jun 13 '11 at 13:47