[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Comparing files in two directories



L.V.Gandhi wrote:
On 6/14/07, *William Pursell* <bill.pursell@gmail.com <mailto:bill.pursell@gmail.com>> wrote:

    L.V.Gandhi wrote:
     > I have two directories A and B. In each directory, I have nearly 1000
     > files with same names. I would like to compare both directories
    and find
     > out which files differ more than say 5 lines. I use kompare and see
     > manually. How to do it in command line easily?

    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?

$(find A -type f) produces a list of files in the directory A.

${file/A/} produces the file name with the leading "A" deleted,
eg:"A/foo" becomes "/foo"

$file B/${file/A/} becomes "A/foo B//foo" which is the
argument list to diff.



Reply to: