您现在的位置是:网站首页> 编程资料编程资料
shell替换文件中的文件路径脚本分享_linux shell_
2023-05-26
360人已围观
简介 shell替换文件中的文件路径脚本分享_linux shell_
用法
参数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脚本操作oracle删除表空间、创建表空间、删除用户_linux shell_
- shell对比文件内容脚本分享_linux shell_
- shell使用mysqld_multi自动做多实例从库脚本_linux shell_
- 使用shell检查并修复mysql数据库表的脚本_linux shell_
- 定时导出mysql本地数据替换远程数据库数据脚本分享_linux shell_
- svn服务器启动和svn服务器重启、停止等操作脚本分享_linux shell_
- 25个好用的Shell脚本常用命令分享_linux shell_
- Shell脚本监控服务器在线状态和邮件报警的方法_linux shell_
- Shell脚本判断IP地址是否合法的方法_linux shell_
- MAC中用Shell脚本批量裁剪各种尺寸的App图标_linux shell_
