0
点赞
收藏
分享

微信扫一扫

【内容替换】shell脚本批量替换文件内容(替换ip及其他配置文件)


0.介绍

1.替换某个文件夹下所有文件及其子文件的内容
2.主要命令:sed -i "s/111/eee/g" $1"/"$file(将文件中所有的111替换为eee)
3.使用方式:
./replace.sh ./
表示:在当前目录下(./)执行该命令 ./replace ./进行替换

1.脚本(replace.sh)

#!/bin/bash
array=(
txt
yml
yaml
properties
js
html
xml
)

function read_dir(){
for file in `ls $1`
do
if [ -d $1"/"$file ];then
# echo "文件夹:" $1"/"$file
read_dir $1"/"$file
else
if [ $file != "replace.sh" ];then
if [[ "${array[@]}" =~ "${file##*.}" ]]; then
echo "文件:" $1"/"$file
sed -i "s/1111111111/eee/g" $1"/"$file
elif [[ ! "${array[@]}" =~ "${file##*.}" ]]; then
echo "忽略文件:" $1"/"$file
fi
fi
fi
done
}

read_dir $1


举报

相关推荐

0 条评论