我在 httpd.conf 文件中有以下虚拟主机
<VirtualHost *:80>
## could be comments
could be any line
could be any line
could be any line
</VirtualHost>
<VirtualHost *:80>
could be any line
## could be comments
could be any line
could be any line
could be any line
could be any line
could be any line
</VirtualHost>
<VirtualHost *:80>
## may have comments
ServerName ppp.com
could be any line
could be any line
could be any line
</VirtualHost>
<VirtualHost *:443>
## could be empty
ServerName zzz.com
could be any line
could be any line
could be any line
</VirtualHost>
我正在尝试将“ServerName abc.com”添加到每个尚未设置 ServerName 的虚拟主机。
我试图在 sed 中做到这一点,但我没有得到任何帮助..有什么帮助吗?
这是我到目前为止...
sed '/^[ \t]*<VirtualHost/,/^[ \t]*<\/VirtualHost/{
/^ServerName/!{
/<VirtualHost/{
/^/a\ServerName abc.com
}
}
}' httpd.conf