Тема: sed - быстро меняем много конфигов

Есть много файлов вот с таким параметром

[root@hstb1 conf]# grep Recycle ./*
./host_hstb1.superserver.lt-dir.conf:  Recycle = yes
./host_pl10.superserver.lt-dir.conf:  Recycle = yes
./host_pl11.superserver.lt-dir.conf:  Recycle = yes
./host_pl12.superserver.lt-dir.conf:  Recycle = yes
./host_pl14.superserver.lt-dir.conf:  Recycle = yes
./host_pl15.superserver.lt-dir.conf:  Recycle = yes
./host_pl18.superserver.lt-dir.conf:  Recycle = yes
./host_pl19.superserver.lt-dir.conf:  Recycle = yes
./host_pl1.superserver.lt-dir.conf:  Recycle = yes
./host_pl20.superserver.lt-dir.conf:  Recycle = no
./host_pl2.superserver.lt-dir.conf:  Recycle = yes
./host_pl3.superserver.lt-dir.conf:  Recycle = yes
./host_pl4.superserver.lt-dir.conf:  Recycle = yes
./host_pl5.superserver.lt-dir.conf:  Recycle = yes
./host_pl7.superserver.lt-dir.conf:  Recycle = yes
./host_pl9.superserver.lt-dir.conf:  Recycle = yes
./host_srv3.superserver1.lt-dir.conf:  Recycle = yes
./host_vnshw03.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw10.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw11.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw12.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw14.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw17.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw19.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw20.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw23.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw24.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw26.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw35.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw36.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw37.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw45.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw47.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw51.superserver.lt-dir.conf:  Recycle = no
./host_vnshw52.superserver.lt-dir.conf:  Recycle = yes
./host_vnshw54.superserver.lt-dir.conf:  Recycle = yes

а надо сделать везде

Recycle = no

одна команда

[root@hstb1 conf]# sed -ie 's/Recycle.*=.*yes/Recycle = no/ig' ./*-dir.conf

все старые файлы копируются как

*-dir.confe

их надо удалить

[root@hstb1 conf]# rm -vf *-dir.confe
removed `host_hstb1.superserver.lt-dir.confe'
removed `host_pl10.superserver.lt-dir.confe'
removed `host_pl11.superserver.lt-dir.confe'
removed `host_pl12.superserver.lt-dir.confe'
removed `host_pl14.superserver.lt-dir.confe'
removed `host_pl15.superserver.lt-dir.confe'
removed `host_pl18.superserver.lt-dir.confe'
removed `host_pl19.superserver.lt-dir.confe'
removed `host_pl1.superserver.lt-dir.confe'
removed `host_pl20.superserver.lt-dir.confe'
removed `host_pl2.superserver.lt-dir.confe'
removed `host_pl3.superserver.lt-dir.confe'
removed `host_pl4.superserver.lt-dir.confe'
removed `host_pl5.superserver.lt-dir.confe'
removed `host_pl7.superserver.lt-dir.confe'
removed `host_pl9.superserver.lt-dir.confe'
removed `host_srv3.superserver1.lt-dir.confe'
removed `host_vnshw03.superserver.lt-dir.confe'
removed `host_vnshw10.superserver.lt-dir.confe'
removed `host_vnshw11.superserver.lt-dir.confe'
removed `host_vnshw12.superserver.lt-dir.confe'
removed `host_vnshw14.superserver.lt-dir.confe'
removed `host_vnshw17.superserver.lt-dir.confe'
removed `host_vnshw19.superserver.lt-dir.confe'
removed `host_vnshw20.superserver.lt-dir.confe'
removed `host_vnshw23.superserver.lt-dir.confe'
removed `host_vnshw24.superserver.lt-dir.confe'
removed `host_vnshw26.superserver.lt-dir.confe'
removed `host_vnshw35.superserver.lt-dir.confe'
removed `host_vnshw36.superserver.lt-dir.confe'
removed `host_vnshw37.superserver.lt-dir.confe'
removed `host_vnshw45.superserver.lt-dir.confe'
removed `host_vnshw47.superserver.lt-dir.confe'
removed `host_vnshw51.superserver.lt-dir.confe'
removed `host_vnshw52.superserver.lt-dir.confe'
removed `host_vnshw54.superserver.lt-dir.confe'
removed `tpl_def_file_set-dir.confe'

и проверить результат

[root@hstb1 conf]# grep Recycle ./*
./host_hstb1.superserver.lt-dir.conf:  Recycle = no
./host_pl10.superserver.lt-dir.conf:  Recycle = no
./host_pl11.superserver.lt-dir.conf:  Recycle = no
./host_pl12.superserver.lt-dir.conf:  Recycle = no
./host_pl14.superserver.lt-dir.conf:  Recycle = no
./host_pl15.superserver.lt-dir.conf:  Recycle = no
./host_pl18.superserver.lt-dir.conf:  Recycle = no
./host_pl19.superserver.lt-dir.conf:  Recycle = no
./host_pl1.superserver.lt-dir.conf:  Recycle = no
./host_pl20.superserver.lt-dir.conf:  Recycle = no
./host_pl2.superserver.lt-dir.conf:  Recycle = no
./host_pl3.superserver.lt-dir.conf:  Recycle = no
./host_pl4.superserver.lt-dir.conf:  Recycle = no
./host_pl5.superserver.lt-dir.conf:  Recycle = no
./host_pl7.superserver.lt-dir.conf:  Recycle = no
./host_pl9.superserver.lt-dir.conf:  Recycle = no
./host_srv3.superserver1.lt-dir.conf:  Recycle = no
./host_vnshw03.superserver.lt-dir.conf:  Recycle = no
./host_vnshw10.superserver.lt-dir.conf:  Recycle = no
./host_vnshw11.superserver.lt-dir.conf:  Recycle = no
./host_vnshw12.superserver.lt-dir.conf:  Recycle = no
./host_vnshw14.superserver.lt-dir.conf:  Recycle = no
./host_vnshw17.superserver.lt-dir.conf:  Recycle = no
./host_vnshw19.superserver.lt-dir.conf:  Recycle = no
./host_vnshw20.superserver.lt-dir.conf:  Recycle = no
./host_vnshw23.superserver.lt-dir.conf:  Recycle = no
./host_vnshw24.superserver.lt-dir.conf:  Recycle = no
./host_vnshw26.superserver.lt-dir.conf:  Recycle = no
./host_vnshw35.superserver.lt-dir.conf:  Recycle = no
./host_vnshw36.superserver.lt-dir.conf:  Recycle = no
./host_vnshw37.superserver.lt-dir.conf:  Recycle = no
./host_vnshw45.superserver.lt-dir.conf:  Recycle = no
./host_vnshw47.superserver.lt-dir.conf:  Recycle = no
./host_vnshw51.superserver.lt-dir.conf:  Recycle = no
./host_vnshw52.superserver.lt-dir.conf:  Recycle = no
./host_vnshw54.superserver.lt-dir.conf:  Recycle = no

Все.

2

Re: sed - быстро меняем много конфигов

На FreeBSD что то не получилось с флагами.

# sed -ie 's/phpnet_//ig' ./*
sed: 1: "s/phpnet_//ig": bad flag in substitute command: 'i'

3

Re: sed - быстро меняем много конфигов

Не большой скриптик в PERL.

#!/usr/bin/perl
use strict;
my $whatWord = 'what_word_you_need_to_exclude';
my $dir = '/home/user/directory';
my @files = `grep -R $whatWord $dir`;
chomp @files;
foreach my $line (@files)
{
 my ($file, $script) = split (':', $line);
 print "\n===> SED in file ".$file."\n";
 `sed -ie 's/$whatWord//g' $file`;
}
#find ./ -name \*.phpe -delete
exit;