0

I have thousands of flat files in two directories dir1 and dir2. Now, I want to generate diff report of the pair of same file names in two other different directories success (if diff is exactly same) and failure (if diff is not same).

For example: if dir1 has files: file1, file2 and if dir2 has files: file2, file3

Then I'd take the diff of dir1/file2 and dir2/file2 only. file1 and file3 will be ignored as they don't have their respective pairs.

How can I do it using shell script? Is it possible using system commands?

4

1 回答 1

1

您没有指定要在“成功”和“失败”目录中看到什么样的报告,因此不包括在解决方案中。此外,使用“cmp”而不是“diff”,因为您没有准确指定您需要“diff”输出以及什么样的输出。

for p1 in dir1/*; do
    f=`basename "$p1"`
    p2="dir2/$f"
    if [ -e "$p2" ]; then
        if cmp --quiet "$p1" "$p2"; then
            echo "$f: success"
        else
            echo "$f: failure"
        fi
    fi
done

用您的报告生成替换“echo”。如有必要,将“cmp”替换为“diff”和适当的选项。

于 2013-05-06T07:28:35.757 回答