So, I wanted to parse the apache config file so I could get the ServerName and the DocumentRoot of each VirtualHost.

awk '/^<VirtualHost*/,/^<\/VirtualHost>/{if(/^<\/VirtualHost>/)p=1;if(/ServerName|DocumentRoot|## User/)out = out (out?OFS:"") (/User/?$3:$2)}p{print out;p=0;out=""}' vhosts.conf

The command will output the info in the format:

ServerName DocumentRoot

or opposite depending on the order in which they appear on the VirtualHost

 

Note: You should exclude those VirtualHosts which are only redirects