Unix find with wildcard directory structure
How about using a for
loop to find the WA
directories, then go from there:
for DIR in $(find /a/b/c -type d -name WA -print); do find $DIR/*/temp/*/*/data -type f \ -exec grep -l "www.domain.com" {} /dev/null \;done
You may be able to get all that in a single command, but I think clarity is more important in the long run.
Assuming no spaces in the paths, then I'd think in terms of:
find /a/b/c -name data -type f |grep -E '/WA/[^/]+/temp/[^/]+/[^/]+/data' |xargs grep -l "www.domain.com" /dev/null
This uses find
to find the files (rather than making the shell do most of the work), then uses the grep -E
(equivalent to egrep
) to select the names with the correct pattern in the path, and then uses xargs
and grep
(again) to find the target pattern.