shell替换程序里的代码关键字

#!/bin/bash

ROOT_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
fi

ifile=$(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
 

本文出自 “Android/Linux@HeFei” 博客,谢绝转载!

你可能感兴趣的:(shell,职场,休闲)