源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

shell替换文件中的文件路径脚本分享

  • 时间:2021-03-06 16:19 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:shell替换文件中的文件路径脚本分享
用法 参数1、写有需要替换路径记录的文本,格式:老路径 老名称 新路径 新名称 参数2、需要替换的文件的目录 参数3、需要替换的文件的类型
[u]复制代码[/u] 代码如下:
#!/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
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部