用法
参数1、写有需要替换路径记录的文本,格式:老路径 老名称 新路径 新名称
参数2、需要替换的文件的目录
参数3、需要替换的文件的类型
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替换文件中的文件路径脚本分享》,本文关键词 shell,替换,文件,中的,路径,;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。