If you want to grep some content in a set of paths, you can do the following:
find <directory> -type f -print0 | grep "/home/user/this path has spaces in it/\"*\"/abc.xyz" | xargs -I {} grep <your_options> -f <patterns> {}
So, <patterns> is a file containing the patterns you want to search in each file from the directory .
Given your answer, this will do what you want:
find "/path\ with\ spaces/" -type f | xargs -I {} grep -H -c -e 2013-01-17 {}
From man grep :
-H, --with-filename Print the file name for each match. This is the default when there is more than one file to search.
Since you want to insert elements into an array, you can do the following:
IFS=$'\n'; array=( $(find "/path\ with\ spaces/" -type f -print0 | xargs -I {} grep -H -c -e 2013-01-17 "{}") )
And then use the values ββlike:
echo ${array[0]} echo ${array[1]} echo ${array[...]}
When using variables to pass parameters, use eval to evaluate the entire string. Follow these steps:
parameters="-H -c" eval "grep ${parameters} file"
source share