shell脚本实现批量修改替换的操作
#!/bin/bash
#set -x
oldIP="JAVA_OPTIONS"
newIP="JAVA_OPTS"
homefile="/data/jenkins-pipeline/pro_metadata" #修改文件所在的目录
#filelist=`grep ${oldIP} -rl ${homefile}` #查找homefile目录下含有oldIP的文件
filelist=`grep "${oldIP}" -rl ${homefile}|awk -F ":" '{print $1}'` #查找homefile目录下含有oldIP的文件
echo $filelist
for file in $filelist
do
count=`echo $file|grep .yaml|wc -l`
if [ ${count} -eq 0 ];then
continue
else
echo $file
# oldIP="\{\{\ "
sed -i 's/'${oldIP}'/'${newIP}'/g' $file
#sed -i 's/'$oldIP'/'$newIP'/g' $file #变量替换时需要用单引号或者双引号
# sed -i 's#'$oldIP'#'$newIP'#g' $file #变量替换时需要用单引号或者双引号
fi
done
点赞!