0

I got a huge httpd.conf files with tons of Virtual Hosts. I'm trying to find a specific virtual host definition (from the all the way to ) where the domain name is either in the ServerName or in the ServerAlias inside the VirtualHost and I need to do it in BASH using either sed or awk.

I tried this but it's not working.

sed '/<VirtualHost\>.?ServerAlias*abc\.com)*?,<\/VirtualHost>/p' web.txt 

Any suggestions please?

This question is not the same as the answer suggested, as the domain name is in the 2nd or 3rd line inside the VirtualHost definition. Here is an example:

<VirtualHost 1.2.3.4:80>
ServerName aaa.info
ServerAlias www.aaa.com aaa.com aaa.local
DocumentRoot /home/someone/public_html/aaa
.....
.....
</VirtualHost>

<VirtualHost 1.2.3.4:80>
ServerName abc.info
ServerAlias www.abc.com abc.com abc.local
DocumentRoot /home/someone/public_html/abc
.....
.....
</VirtualHost>

<VirtualHost 1.2.3.4:80>
ServerName example.info
ServerAlias www.example.com example.com example.local
DocumentRoot /home/someone/public_html/example
.....
.....
</VirtualHost>

Sometime, the domain is declared in the ServerName and sometime in the ServerAlias.

EDIT: I've done a bit of research, the answer is:

awk 'BEGIN{RS="<VirtualHost"}/abc.com/{sub(/VirtualHost>.*/,"VirtualHost>"); print RS$0}' httpd.conf
Hetzbh
  • 1,339
  • 1
  • 8
  • 3

0 Answers0