linux shell比较两个文件夹下的文本内容

来源:互联网 发布:心彻为知 知彻为德出自 编辑:程序博客网 时间:2024/04/30 01:53
#!/bin/sh


if [ $# -ne 2 ]

then
    echo Usage: compare.sh fold_name_1 fold_name_2
    exit
fi

if [ ! -$1 ]
then
    echo $1 is not a 
    exit
fi

if [ ! -$2 ]
then
    echo $2 is not a 
    exit
fi

fold1=$(echo $1 | sed 's|\(^[^/]*\).*|\1|')
fold2=$(echo $2 | sed 's|\(^[^/]*\).*|\1|')

compareFOLD()
{
    for file in $1/*
    do
        if [ -$file ] then
            compareFOLD $file
        elif [ -$file ]
        then
            if [ ! -$file ]
            then
                file2=$(echo $file | sed "s|^.[^/]*\(.*\)|$fold2\1|")
                diff $file $file2
                if [ $? -ne 0 ]
                then
                    echo -"\033[32m"$file
                    echo $file2
                    echo -"\033[0m"---------------------------------------------------------------------
                fi
            fi
        fi
    done
}

compareFOLD $fold
1
0 0
原创粉丝点击