1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 【内容替换】shell脚本批量替换文件内容(替换ip及其他配置文件)

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

时间:2023-05-26 22:02:08

相关推荐

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

0.介绍

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

1.脚本(replace.sh)

#!/bin/basharray=(txtymlyamlpropertiesjshtmlxml)function read_dir(){for file in `ls $1`doif [ -d $1"/"$file ];then# echo "文件夹:" $1"/"$fileread_dir $1"/"$fileelseif [ $file != "replace.sh" ];thenif [[ "${array[@]}" =~ "${file##*.}" ]]; thenecho "文件:" $1"/"$filesed -i "s/1111111111/eee/g" $1"/"$fileelif [[ ! "${array[@]}" =~ "${file##*.}" ]]; thenecho "忽略文件:" $1"/"$filefififidone}read_dir $1

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。