I would like to search all files containing an association of strings (here the files should contain 'arthur' AND ('dni' OR 'deni') for instance) in a directory and subdirectories. After some search I came up with the following code:egrep -li 'arthur' `egrep -lir 'dni|deni' /path/to/files/`the trouble is I get error messages because many files and directories contain spaces. Is there a way to go round this issue?
grep and directories containing spaces
shell;grep;filenames;command substitution
You would be better off using find and passing a shell command to -exec:find /path/to/files -type f -exec sh -c 'for file do    egrep -iq dni|deni $file && egrep -li arthur $file    done' sh {} +This would work with filenames containing spaces.Dissecting the shell command:egrep -iq dni|deni $file && egrep -li arthur $fileSaying egrep -iq dni|deni $file would return true if the pattern matches.  So it would execute egrep -li arthur $file which would list the file if this command matches the pattern specified.In fact, you don't even need a shell:find /path/to/files -type f -exec egrep -iq dni|deni {} \; \                            -exec egrep -li arthur {} \;(-exec predicates with the ; terminator can also be used as conditions (based on the exit status of the executed command)).