title: sed: conditional merge of multiple lines
body: <p>I need to merge line of a file using sed based on a pattern. eg:</p>
  
  <p>Input File:</p>
  
  <pre><code>X1 A B C D E F
  
  \+ G H I J 1 
  
  \+ LK T PP E OO 2
  
  X2 DDF F Y 
  
  \+ J W Q 
  </code></pre>
  
  <p>....</p>
  
  <p>OutPut Expected:</p>
  
  <pre><code>X1 A B C D E F G H I J 1 LK T PP E OO 2
  
  X2 DDF F Y J W Q 
  
  ..
  </code></pre>
  
  <hr>
  
  <p>I would like to equivalent of wat is possible in vi editor (:%s/\n+/ /g)</p>
  
  <p>Searching the web I found a solution, which logically should have worked</p>
  
  <blockquote>
    <p>sed -e '{:a; N; s/\n+/ /g; ta}' infile</p>
  </blockquote>
  
  <p>But this command defies my understanding and logic, and has produced output</p>
  
  <pre><code>X1 A B C D E F
  
  \+ G H I J 1 LK T PP E OO 2
  X2 DDF F Y 
  
  \+ J W Q 
  </code></pre>
  
  <p>....</p>
  
  <p>Any ideas are welcome, &amp; Thanks in advance</p>
  
  <p>Srisurya</p>