perl中替换文本一例
发布时间:2020-12-16 00:41:19 所属栏目:大数据 来源:网络整理
导读:由于工作需要,需要批量建立网站,修改配置文件。开始时用sed去批量修改的,最后改装成perl了。 #!/usr/bin/perl while(){ chomp; @line=split(/s+/,$_); open FH," /home/test/$line[0]/wp-config.php"; my @webfile; while(FH){ ????????s/(ME|ER)','root
由于工作需要,需要批量建立网站,修改配置文件。开始时用sed去批量修改的,最后改装成perl了。
#!/usr/bin/perl
while(<>){ chomp; @line=split(/s+/,$_); open FH,"< /home/test/$line[0]/wp-config.php"; my @webfile; while(<FH>){ ????????s/(ME|ER)','root/$1','$line[1]/g; ????????push @webfile,$_; } close FH; open FH,"> /home/test/$line[0]/wp-config.php"; print FH for @webfile; #相当于foreach $mm (@webfile){
???????????????????????????????#?????print?FH $mm;????????
??????????????????????????????? #???
????????????????????????????????#??? ?? }
close FH; }
输入的文件
域名????? 数据库名称
a1.com?????? a1_db
a2.com??????? a2_db
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |