本文共 2026 字,大约阅读时间需要 6 分钟。
需求:
扩展名类型: .php .html .shtml .inc 将替换为替换 替换为:_(*).js 替换为:(*)/(*).js 脚本1: #!/bin/bashROOT_DIR='/root/temp/wow'
KEYWORD='ad_union' KEYWORD2='advertisement'#for i in $(find $ROOT_DIR -name "*.*" -exec grep "$KEYWORD" {} \;)
for i in $(find $ROOT_DIR -name "*.*") do ifile=$(grep "$KEYWORD" $i) if [ "$?" -eq "0" ] then FILE_NUMBER=$(echo $ifile | awk -F"\"" '{print $2}' | awk -F"/" '{print $NF}' | awk -F"." '{print $1}' | awk -F"_" '{print $NF}') #sed -i "s#ad\_union\_[0-9][0-9]#union\_$FILE_NUMBER#g" $i sed -i "s#ad\_union\_$FILE_NUMBER#union\_$FILE_NUMBER#g" $i fiifile=$(grep "$KEYWORD2" $i)
if [ "$?" -eq "0" ] then FILE_NUMBER2=$(echo $ifile | awk -F"\"" '{print $2}' | awk -F"/" '{print $NF}' | awk -F"." '{print $1}' | awk -F"_" '{print $NF}') sed -i "s#advertisement\/$FILE_NUMBER2\/ad\_$FILE_NUMBER2#upload\/$FILE_NUMBER2\/$FILE_NUMBER2#g" $i fi done
脚本2: #!/bin/bash
EXT_ARRAY=("*.php" "*.inc" "*.html" "*.shtml")
EXT_ARRAY_LEN=${#EXT_ARRAY[@]} ROOT_DIR='/root/temp/wow' KEYWORD='ad_union' KEYWORD2='advertisement'#i=0
#while [ $i -lt $EXT_ARRAY_LEN ] #do # find $ROOT_DIR -name "${EXT_ARRAY[$i]}" | while read f # do # sed -i 's#union\/ad_union_5\.js#union\/union_5\.js#g' $f # sed -i 's#advertisement\/27\/ad_27\.js#upload\/27\/27\.js#g' $f # done # let i++ #done#for i in $(find $ROOT_DIR -name "*.*" -exec grep "$KEYWORD" {} \;)
for i in $(find $ROOT_DIR -name "*.*") do ifile=$(grep "$KEYWORD" $i) if [ "$?" -eq "0" ] then FILE_NUMBER=$(echo $ifile | awk -F"/" '{print $NF}' | awk -F"." '{print $1}' | awk -F"_" '{print $NF}') #sed -i "s#ad\_union\_[0-9][0-9]#union\_$FILE_NUMBER#g" $i sed -i "s#ad\_union\_$FILE_NUMBER#union\_$FILE_NUMBER#g" $i fiifile=$(grep "$KEYWORD2" $i)
if [ "$?" -eq "0" ] then FILE_NUMBER2=$(echo $ifile | awk -F"/" '{print $NF}' | awk -F"." '{print $1}' | awk -F"_" '{print $NF}') sed -i "s#advertisement\/$FILE_NUMBER2\/ad\_$FILE_NUMBER2#upload\/$FILE_NUMBER2\/$FILE_NUMBER2#g" $i fi done这两个脚本分别执行替换程序里的代码内容。
本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/456622
转载地址:http://gzsxa.baihongyu.com/