手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >shell替换文件中的文件路径脚本分享
shell替换文件中的文件路径脚本分享
摘要:用法参数1、写有需要替换路径记录的文本,格式:老路径老名称新路径新名称参数2、需要替换的文件的目录参数3、需要替换的文件的类型复制代码代码如...

用法

参数1、写有需要替换路径记录的文本,格式:老路径 老名称 新路径 新名称

参数2、需要替换的文件的目录

参数3、需要替换的文件的类型

复制代码 代码如下:

#!/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替换文件中的文件路径脚本分享】相关文章:

linux中批量修改文件名的脚本代码

shell去掉文件中空行(空白行)的方法详解

Shell脚本注释写法

Shell实现系统时间和BIOS时间同步校准脚本分享

shell监控脚本 准备工作分享

linux下保留文件系统下剩余指定数目文件的shell脚本

sed删除文件中的一行内容的脚本代码

mysql源码安装脚本分享

shell对比文件内容脚本分享

定时导出mysql本地数据替换远程数据库数据脚本分享

精品推荐
分类导航