Originally Posted by grail
while read -r FILE
find dir2 -type f -name "$FILE"
done< <(find dir1 -type f -printf "%f\n" | sed 's/[^[:alnum:]]/\\&/g')
It seems to work and *bonus* even works if files under dir1
are buried in a completely different hierarchy than files under dir2
. It looks a little over-engineered though and I'm not sure all that complexity is really doing anything useful.
You're escaping all non-alphanumeric characters
. I cannot think of a scenario where this would not
work, but it goes further than necessary for my scenario.
Is it really necessary to use process substitution for gathering the file names from dir1
? If so, then why?
I tried piping the dir1
file names into the loop and it seemed to work perfectly. When might piping not
foo$ find dir1 -type f -printf "%f\n" | sed 's/[^[:alnum:]]/\\&/g' |
> while read -r FILE
> find dir2 -type f -name "$FILE"
Thanks very much for this example, although I still prefer
Originally Posted by http://www.linuxquestions.org/questions/programming-9/bash-find-how-to-avoid-%5B-%5D-pattern-matching-in-file-names-expanded-from-%24var-875990/#post4331213
because IMHO it is more graceful and easier to type.