title: egrep to match multiple lines
body: <p>I have several Apache vHost configurations across several hosts.  I'm trying to write a Bash script that will iterate through each host and search the <code>.conf</code> file on each one, pulling out the first (only the first) <code>&lt;VirtualHost&gt;</code> block. I've tried writing a regex to match it, but it's just not working. Here's the code I've tried:</p>
  
  <pre><code>    #!/bin/bash
      egrep -o '(\&lt;VirtualHost\&gt;)(.*)(\&lt;\/VirtualHost\&gt;)' -m1
  </code></pre>
  
  <p>Since <code>.*</code> doesn't match newlines, I even tried this:</p>
  
  <pre><code>    #!/bin/bash
      egrep -o '(\&lt;VirtualHost\&gt;)(.*[\S]*)(\&lt;\/VirtualHost\&gt;)' -m1
  </code></pre>
  
  <p>I still get nothing. :-(</p>
  
  <p>I don't understand what I'm doing wrong here.  Here is a sample of the data I'm trying to match:</p>
  
  <pre><code>    &lt;VirtualHost apache-frontend:80&gt;
              ServerAdmin     mysite@domain.com
              ServerName      domain.com
              DocumentRoot    /path/to/my/doc/root
  
              RewriteEngine   On
              Include         include.d/global/rewrite.conf
              RewriteRule     ^(.*)$ http://www.domain.com$1 [R=301,L]
      &lt;/VirtualHost&gt;
  
      &lt;VirtualHost apache-frontend:80&gt;
              ServerAdmin     mysite@domain.com
              ServerName      domain.com
              DocumentRoot    /path/to/my/doc/root
  
              RewriteEngine   On
              Include         include.d/global/rewrite.conf
              RewriteRule     ^(.*)$ http://www.domain.com$1 [R=301,L]
      &lt;/VirtualHost&gt;
  
      &lt;VirtualHost apache-frontend:80&gt;
              ServerAdmin     mysite@domain.com
              ServerName      domain.com
              DocumentRoot    /path/to/my/doc/root
  
              RewriteEngine   On
              Include         include.d/global/rewrite.conf
              RewriteRule     ^(.*)$ http://www.domain.com$1 [R=301,L]
      &lt;/VirtualHost&gt;
  </code></pre>