Quote:
Originally Posted by grail
Code:
while read -r FILE
do
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 work?
Code:
foo$ find dir1 -type f -printf "%f\n" | sed 's/[^[:alnum:]]/\\&/g' |
> while read -r FILE
> do
> find dir2 -type f -name "$FILE"
> done
dir2/subdir2/file2
dir2/subdir2/file[a1]
dir2/subdir2/deepdir/messed[[up]name
dir2/subdir1/file1
Thanks very much for this example, although I still prefer
Quote:
|
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
konsolebox's solution
|
because IMHO it is more graceful and easier to type.
