title: How to join multiple lines separated by a pattern into one in Vi
body: <p>E.g.:</p>
  
  <p>cat file1</p>
  
  <pre><code>a="Ajim 123 Bagwan"
  b="Johnny 120 Boy"
  c="Bad 777 Girl"
  &lt;SHOUT&gt;
  a="Aj 30 Bag"
  b="John 10 Boycott"
  c="Badlands 20 Malick"
  &lt;SHOUT&gt;
  .........
  </code></pre>
  
  <p>My output should look like this:</p>
  
  <pre><code>"Ajim 123 Bagwan" | "Johnny 120 Boy" | "Bad 777 Girl"
  &lt;SHOUT&gt;
  "Aj 30 Bag" | "John 10 Boycott" | "Badlands 20 Malick"
  &lt;SHOUT&gt;
  </code></pre>
  
  <p>i.e. the set of 3 lines(or just values will do too) that are separated by a pattern <code>"&lt;SHOUT&gt;"</code> should get concatenated with some separator in them. What is the best way to do this?</p>
  
  <p>The way I've been trying this is by search replacing(using %s/A/B in vi) the pattern (spanning 2 lines) "\Nb=" and "\Nc=" by a pipe(|). I've done this way before but I am just not getting it. \N being the Newline character (Control-M)</p>
  
  <p>Edit:</p>
  
  <p>I was able to figure out a way to do this using simple search replace. I did the following from vi. </p>
  
  <pre><code>:%s/"\nb="/|/g
  :%s/"\nc="/|/g
  </code></pre>
  
  <p>Where \n is newline character. </p>
  
  <p>These two commands replaced every occurrence of "\nb=" and "\nc=" with a pipe(|) character. 
  Then I just replaced the beginning a=" and the ending " with a null using similar command. </p>
  
  <pre><code>:%s/a="//g
  :%s/"//g
  </code></pre>
  
  <p>Thanks everyone for your answers.  </p>