#!/bin/bash #set -x oldIP=172.17.39.135 newIP=172.17.98.115 homefile=/usr/local/ims/ filelist=`grep $oldIP -rl $homefile` #查找homefile目录下含有oldIP的文件 echo $filelist for file in $filelist do sed -i 's/'$oldIP'/'$newIP'/g' $file #变量替换时需要用单引号或者双引号 done exit