Re: Comparing files in two directories
L.V.Gandhi wrote:
> William Pursell wrote:
> > Here's a scriptlet that will print the name of all the files for
> > which diff produces more than 5 lines of output. (Which is not quite
> > to say that they differ in 5 lines, but it's close).
> >
> > for file in $(find A -type f); do if test $(diff $file B/${file/A/} | wc -l) -gt 5; then echo $file; fi; done
> >
>
> Can you please explain both $ part?
$(SOME COMMAND HERE) is "command substitution". The "SOME COMMAND
HERE" part is executed and the output replaces the $(...) part. The
first part runs 'find A -type f' as a command and the output is placed
there for the for loop to process.
Setup:
mkdir t
cd t
touch a b c
This:
for file in $(find . -type f); do
That is the same as:
for file in ./a ./b ./c; do
Same thing for the $(diff ...) part. The output replaces the $(...) part.
The $file part is variable expansion. First it will be set to the
first thing, in my example "./a" and then the next, "./b" and so forth
through all of the strings in the for loop.
Bob
Reply to: