What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info.
Basically my file looks like this:
...
<VirtualHost *:>
ServerName server.name1.com
ServerAlias svrname
Redirect Permanent / http://www.sitename1.gov
# Disable HTTP TRACE Support (see http://www.kb.cert.org/vuls/id/867593)
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</VirtualHost>
<VirtualHost *:>
ServerName www.servername2
ServerAlias srvname2
ServerAlias srvname.2.com
DocumentRoot /location/of/document/root
DirectoryIndex index.shtml
ScriptAlias /cgi-bin/ /tst/cgi-bin/
ErrorDocument 403 http://www.error.com/errors/error403.html
# ErrorDocument 404 http://www.error.com/errors/error404.html
# Disable HTTP TRACE Support (see http://www.kb.cert.org/vuls/id/867593)
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</VirtualHost>
...
And I want it to look like this:
...
<VirtualHost *:>
ServerName server.name1.com
<VirtualHost *:>
ServerName www.servername2
DocumentRoot /location/of/document/root
...
There a simple or not so simple awk script for this? Thanks.