title: Joining lines that matches specific conditions in bash
body: <p>I need a command that will join lines if:<br>
  -following line starts with more than 5 spaces<br>
  -length of the joined lines won't be greater than 79 characters<br>
  -those lines are not between lines with pattern1 and pattern2<br>
  -same as above but with another set of patterns, like pattern3 and pattern4</p>
  
  <p>It will work on a file like this:</p>
  
  <blockquote>
  <pre><code>Long line that contains too much text for combining it with following one  
  That line cannot be attached to the previous becouse of the length
  This one also 
  becouse it doesn't start with spaces
  
  This one 
       could be
       expanded
  
  pattern1
  here are lines
       that shouldn't be 
       changed
  pattern2
  
  Another line
       to grow
  </code></pre>
  </blockquote>
  
  <p>After running the command, output should be:</p>
  
  <blockquote>
  <pre><code>Long line that contains too much text for combining it with following one  
  That line cannot be attached to the previous becouse of the length
  This one also 
  becouse that one doesn't start with spaces
  
  This one could be expanded
  
  pattern1
  here are lines
       that shouldn't be 
       changed
  pattern2
  
  Another line to grow
  </code></pre>
  </blockquote>
  
  <p>It can't move part of the line.</p>
  
  <p>I'm using bash 2.05 sed 3.02 awk 3.1.1 and grep 2.5.1 and i don't know how to solve this problem :)</p>