<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Natural

     

    [demo]sed字符串替換

    找出Z:\A、Z:\B目錄下所有內容帶“APPLE“的文件,把"APPLE"替換成"ORANGE",并輸出到Z:\C相應的目錄下

      1 #!/bin/sh
      2 # Auto replace the files' content and copy them to the specified directory.
      3 
      4 SEARCH_WORD='APPLE'
      5 REPLACE_WORD='ORANGE'
      6 
      7 SRC_DIR_ARRAY=(
      8 'Z:/A'
      9 'Z:/B'
     10 )
     11 
     12 OUTPUT='Z:/C'
     13 
     14 global_lastDir_pre=''
     15 declare -i count=0
     16 
     17 function checkFileDir
     18 {
     19     local fileNameWithPath=$1
     20     local dirPre=${fileNameWithPath%/*}
     21     local tempPath=${OUTPUT}/${dirPre}
     22     global_lastOutput=$OUTPUT/$fileNameWithPath
     23     
     24     if [ ! -"$tempPath" ]
     25     then
     26         tar -cf - "$fileNameWithPath" | tar -"$OUTPUT" -xf -
     27         rm -"$global_lastOutput"
     28     fi
     29 
     30 }
     31 
     32 function replaceFile
     33 {
     34     local fileNameWithPath=${1#*/}
     35     local regix=$2
     36     local thisDir_pre=${fileNameWithPath%/*
     37     
     38     if [ "$thisDir_pre" = "$global_lastDir_pre" ]
     39     then
     40         sed "$regix" "$fileNameWithPath" > "$global_lastOutput"
     41         continue
     42     fi
     43 
     44     checkFileDir "$fileNameWithPath"
     45     global_lastDir_pre=$thisDir_pre
     46 
     47     sed "$regix" "$fileNameWithPath" > "$global_lastOutput"
     48 }
     49 
     50 function echoNote
     51 {
     52     echo "Wrong directory detected. Please check it !"
     53 }
     54 
     55 function init
     56 {
     57     for src_dir in ${SRC_DIR_ARRAY[*]}
     58     do
     59         if [ ! -"$src_dir" ]
     60         then
     61             echoNote
     62             echo "SRC_DIR_ARRAY: '$src_dir'"
     63             exit
     64         fi
     65     done
     66     
     67     if [ ! -"$OUTPUT" ]
     68     then
     69         echoNote
     70         echo "OUTPUT: '$OUTPUT'"
     71         exit
     72     fi
     73     
     74     rm -rf "$OUTPUT"
     75     mkdir "$OUTPUT"
     76 
     77 }
     78 
     79 
     80 echo -"----------------------------BEGIN--------------------------------\n"
     81 
     82 init
     83 for src_dir in ${SRC_DIR_ARRAY[*]}
     84 do
     85 
     86     cd "$src_dir"
     87     list=`find . -type f | xargs grep -"$SEARCH_WORD"`
     88     #list=`find . -type f | xargs grep -il "$SEARCH_WORD"`    # ignore case
     89     for line in $list
     90     do
     91         grep -Hn "$SEARCH_WORD" "$line" >> "$OUTPUT/log.txt"
     92         #grep -iHn "$SEARCH_WORD" "$line" >> "$OUTPUT/log.txt"    # ignore case
     93         count=count+1
     94         echo $line
     95         replaceFile "$line" "s/$SEARCH_WORD/$REPLACE_WORD/g"
     96         #replaceFile "$line" "s/$SEARCH_WORD/$REPLACE_WORD/Ig"    # ignore case
     97     done
     98 
     99 done
    100 
    101 echo -"\n----------summary----------"
    102 echo "total files size: $count"
    103 
    104 echo "----------------------------END--------------------------------"
    105 

    posted on 2012-02-21 15:51 此號已被刪 閱讀(348) 評論(0)  編輯  收藏 所屬分類: Linux

    導航

    統計

    常用鏈接

    留言簿(8)

    隨筆分類(83)

    隨筆檔案(78)

    文章檔案(2)

    相冊

    收藏夾(7)

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 精品国产日韩亚洲一区在线| 亚洲中文无码a∨在线观看| 欧洲亚洲国产精华液| 97无码免费人妻超级碰碰夜夜| 麻豆亚洲av熟女国产一区二| 无码少妇精品一区二区免费动态| 亚洲大成色www永久网站| 免费看少妇高潮成人片| 亚洲成AV人在线播放无码| 久久国产精品免费观看| 亚洲黄网在线观看| 2019中文字幕在线电影免费 | 国产亚洲午夜高清国产拍精品| 精品久久久久久久久免费影院| 一级毛片直播亚洲| 午夜免费国产体验区免费的| 少妇人妻偷人精品免费视频 | 久久精品国产精品亚洲色婷婷| 国产成人AV片无码免费| 久久精品a亚洲国产v高清不卡 | 青青视频观看免费99| 亚洲综合偷自成人网第页色| 高清国语自产拍免费视频国产| 黄页网站在线视频免费| 最近最好的中文字幕2019免费| 亚洲av无码专区在线电影天堂| 免费国产一级特黄久久| 精品国产免费一区二区三区香蕉| 久久精品国产亚洲AV无码娇色 | 无码国产精品一区二区免费式影视 | 成人男女网18免费视频| 老司机午夜精品视频在线观看免费| 久久久精品国产亚洲成人满18免费网站| 免费看少妇高潮成人片| 亚洲最大无码中文字幕| 亚洲综合激情另类专区| 91免费国产在线观看| 高清免费久久午夜精品| 亚洲熟妇无码久久精品| 亚洲精品网站在线观看不卡无广告 | 亚洲视频一区二区三区四区|