国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Linux > 正文

shell替換文件中的文件路徑腳本分享

2019-10-26 18:39:56
字體:
供稿:網(wǎng)友

用法
參數(shù)1、寫有需要替換路徑記錄的文本,格式:老路徑 老名稱 新路徑 新名稱
參數(shù)2、需要替換的文件的目錄
參數(shù)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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 响水县| 平舆县| 华池县| 海宁市| 博白县| 湖北省| 洮南市| 浮山县| 营口市| 竹北市| 准格尔旗| 武安市| 济阳县| 澜沧| 竹山县| 梧州市| 玛纳斯县| 石林| 正宁县| 邵东县| 六盘水市| 同心县| 墨玉县| 汝城县| 上犹县| 和顺县| 东乡县| 阳信县| 天门市| 昌吉市| 青海省| 武胜县| 志丹县| 临夏县| 新丰县| 建瓯市| 大英县| 喜德县| 饶河县| 德保县| 沙坪坝区|