<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)

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 男女男精品网站免费观看 | 精品国产_亚洲人成在线| 香蕉97超级碰碰碰免费公| 91亚洲一区二区在线观看不卡| 一级做a爰全过程免费视频| 国产精品免费αv视频| 亚洲国产小视频精品久久久三级| 黄床大片30分钟免费看| 亚洲无码精品浪潮| 97无码人妻福利免费公开在线视频| 国产AV无码专区亚洲精品| 久久免费动漫品精老司机| 亚洲视频在线观看地址| 99在线精品免费视频九九视| 国产成人亚洲合集青青草原精品| 美女被免费视频网站a国产| 国产精品亚洲专一区二区三区| 在线免费中文字幕| 亚洲理论片中文字幕电影| 成年男女男精品免费视频网站| 亚洲国产成人AV网站| 无码专区一va亚洲v专区在线 | 久久久亚洲欧洲日产国码农村| 91高清免费国产自产拍2021| 亚洲日本久久一区二区va| 日韩免费在线观看| 高清永久免费观看| 亚洲日韩乱码中文无码蜜桃 | 久久精品亚洲男人的天堂| 日本免费中文字幕| 亚洲第一成人在线| 亚洲国产精品视频| 久久国产免费一区二区三区| 中文字幕在线日亚洲9| 最近中文字幕2019高清免费| 一区二区亚洲精品精华液| 一本岛高清v不卡免费一三区| 美女视频黄.免费网址 | 亚洲高清国产拍精品熟女| 日韩亚洲变态另类中文| 4399好看日本在线电影免费|