Let's say I want to compare the files with the same filename between these two directories:
/tmp/datadir/dir1/dir2/
and
/datadir/dir1/dir2/
It is required to sort them before comparing.
I am currently in the /tmp
directory, and I tried to run this find
with the exec
option:
find datadir -type f -exec sdiff -s <( sort {} ) <( sort "/"{} ) \;
But, it gives me an error
sort: open failed: {}: No such file or directory
sort: open failed: /{}: No such file or directory
However, the below command works fine, but the data is not sorted for proper comparison.
find data -type f -exec sdiff -s {} "/"{} \;
How can I fix this problem?
Best Answer
The replacement of
{}
is done byfind
and happens after the evaluation of the process substitution (<(…)
) and such in your code.Using
bash -c
:Or to avoid running one
bash
instance per file: