H5W3
当前位置:H5W3 > 其他技术问题 > 正文

文件对比Shell 求更好方案

differ=$(diff -rq $1 $2| awk {‘print $2,$3,$4’} );
for file in $differ

do
    echo $file
done

$file 输出如下

/home/test/system/app.text
and
/home/vgg/system/app.text

/home/test/system/app1.text
and
/home/vgg/system/app2.text

in
/home/test/system:
app.txt

我想让其

vimdiff 旧文件 新文件

确认无误后

cp /home/test/system/app.txt /home/vgg/system/app.txt

如果是只是单独的某个文件有的话 in ...

cp /home/test/system/app.txt /home/vgg/system/app.txt

回答:

# ---------------------------------------- Function ---------------------------------------- #
function checkFilesDiff()
{
    # diff -c -a -b  -r -q -P  $1 $2

    homeq=($(diff -rq $1 $2 | grep -Ff $3 | grep -Fvf $noGrep|awk {'print $2'} ));
    mydir=($(diff -rq $1 $2 | grep -Ff $3 | grep -Fvf $noGrep|awk {'print $4'} ));

    i=0  
    while [[ i -lt ${#homeq[@]} ]]; do  
        vimdiff  ${mydir[i]} ${homeq[i]}
        deploy_confirm " 修改确认 ${mydir[i]} ?"
        if [ 1 != $? ]; then
            let i++  
            continue;
        fi
        sleep 1
        cp ${mydir[i]} ${homeq[i]}
        let i++  
    done  
}

回答:

可以做MD5或者哈希检验
参考http://blog.useasp.net/archiv…

本文地址:H5W3 » 文件对比Shell 求更好方案

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址