I'm trying to find files with a specific filename extension, containing a specific string, in a directory tree where directory and file names may contain spaces, then put it into an array with one complete path per element.
With the following command I can obtain a list with quoted paths and load it into the array but the assignment escapes the quotes and each element gets a space-delimited substring. I think it's a word-splitting problem but am not sure how to fix it.
Code:
matching_files=($(find . -type f -iname "*.txt" -exec grep -l "MATCH" '{}' \;| sed -n 's/\(.*\)$/\"\1\"/p'|tr "\n" " "))