替换文件中的文件路径

2015-03-10 0 469
替换文件中的文件路径
#!/bin/sh

function _replace(){
basepath=$0
> $basepath.log
i=1
while read line
do
        echo "start===================================================================================" >> $basepath.log
        oldpath=`echo $line|awk '{print $1$2}'|sed 's/^\///g'`
        newpath=`echo $line|awk '{print $3$4}'|sed 's/^\///g'`
        echo $oldpath >> $basepath.log
        echo $newpath >> $basepath.log
        if [ "$oldpath" != "" ] && [ "$newpath" != "" ];then
                refiles=`grep $oldpath -irl --include="*.$3" $2`
                for refile in $refiles
                do
                        sed -i 's#'$oldpath'#'$newpath'#ig' $refile
                        echo $refile >> $basepath.log
                done
	    fi
        echo "end=====================================================================================" >> $basepath.log
        echo "=">> $basepath.log
        echo $i >> $basepath.log
        echo "=">> $basepath.log
i=$(($i+1))
done < $1
}

if [ "$1" != "" ] || [ "$2" != "" ] || [ "$3" != "" ];then
_replace $1 $2 $3
else
echo "use like this:$basepath file filepath type"
fi

遇见资源网 shell 替换文件中的文件路径 http://www.ox520.com/16862.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务