Salut,
Proposition avec une variable.
Le fichier
test_httpd.conf :
<VirtualHost azerty>
DocumentRoot /mon/document/root
DirectoryIndex index.php index.html
ServerName url.domaine.com
ErrorLog /mon/log/erreur
CustomLog /ma/log
<IfModule mod_php5.c>
php_admin_flag safe_mode Off
php_value max_execution_time 120
php_admin_value max_input_time 60
php_admin_flag log_errors On
php_admin_value cgi.force_redirect 0
php_admin_flag file_uploads On
php_admin_value upload_max_filesize 50M
php_admin_value post_max_size 50M
php_value memory_limit 64M
</IfModule>
</VirtualHost>
<VirtualHost toto-azerty>
DocumentRoot /mon/document/root
DirectoryIndex index.php index.html
ServerName url.domaine.com
ErrorLog /mon/log/erreur
CustomLog /ma/log
<IfModule mod_php5.c>
php_admin_flag safe_mode Off
php_value max_execution_time 120
php_admin_value max_input_time 60
php_admin_flag log_errors On
php_admin_value cgi.force_redirect 0
php_admin_flag file_uploads On
php_admin_value upload_max_filesize 50M
php_admin_value post_max_size 50M
php_value memory_limit 64M
</IfModule>
</VirtualHost>
<VirtualHost qsdfgh>
DocumentRoot /mon/document/root
DirectoryIndex index.php index.html
ServerName url.domaine.com
ErrorLog /mon/log/erreur
CustomLog /ma/log
<IfModule mod_php5.c>
php_admin_flag safe_mode Off
php_value max_execution_time 120
php_admin_value max_input_time 60
php_admin_flag log_errors On
php_admin_value cgi.force_redirect 0
php_admin_flag file_uploads On
php_admin_value upload_max_filesize 50M
php_admin_value post_max_size 50M
php_value memory_limit 64M
</IfModule>
</VirtualHost>
<VirtualHost toto-qsdfgh>
DocumentRoot /mon/document/root
DirectoryIndex index.php index.html
ServerName url.domaine.com
ErrorLog /mon/log/erreur
CustomLog /ma/log
<IfModule mod_php5.c>
php_admin_flag safe_mode Off
php_value max_execution_time 120
php_admin_value max_input_time 60
php_admin_flag log_errors On
php_admin_value cgi.force_redirect 0
php_admin_flag file_uploads On
php_admin_value upload_max_filesize 50M
php_admin_value post_max_size 50M
php_value memory_limit 64M
</IfModule>
</VirtualHost>
Le fichier
a_suppr.txt :
azerty
qsdfgh
Puis passer les commandes suivantes :
cp test_httpd.conf test_httpd.conf.sav # Sauvegarde car on va modifier directement dans le fichier
while read VIRTHOST
do
sed -i '\|<VirtualHost '"$VIRTHOST"'>|,\|</VirtualHost>|d' test_httpd.conf
done < a_suppr.txt
Le fichier
test_httpd.conf suite à la manip :
<VirtualHost toto-azerty>
DocumentRoot /mon/document/root
DirectoryIndex index.php index.html
ServerName url.domaine.com
ErrorLog /mon/log/erreur
CustomLog /ma/log
<IfModule mod_php5.c>
php_admin_flag safe_mode Off
php_value max_execution_time 120
php_admin_value max_input_time 60
php_admin_flag log_errors On
php_admin_value cgi.force_redirect 0
php_admin_flag file_uploads On
php_admin_value upload_max_filesize 50M
php_admin_value post_max_size 50M
php_value memory_limit 64M
</IfModule>
</VirtualHost>
<VirtualHost toto-qsdfgh>
DocumentRoot /mon/document/root
DirectoryIndex index.php index.html
ServerName url.domaine.com
ErrorLog /mon/log/erreur
CustomLog /ma/log
<IfModule mod_php5.c>
php_admin_flag safe_mode Off
php_value max_execution_time 120
php_admin_value max_input_time 60
php_admin_flag log_errors On
php_admin_value cgi.force_redirect 0
php_admin_flag file_uploads On
php_admin_value upload_max_filesize 50M
php_admin_value post_max_size 50M
php_value memory_limit 64M
</IfModule>
</VirtualHost>
EDIT : concernant le grep sur un mot
Un
- délimite un mot c'est pour ça que la commande
grep -w azerty sort aussi une ligne contenant
toto-azerty.
Par contre, elle ne sortirait pas la ligne pour le mot
toto_azerty.