title: Bash script to split file into two files while changing output file during processing
body: <p>I am trying to split a text file into two different files, file looks something like this:</p>
  
  <pre><code>//ABC12//burrito (line of text)
  (line of text)
  (line of text)
  etc
  //ABC12//taco (line of text)
  (line of text)
  (line of text)
  etc
  //ABC12//taco (line of text)
  (line of text)
  (line of text)
  etc
  //ABC12//burrito (line of text)
  (line of text)
  (line of text)
  etc
  </code></pre>
  
  <p>So I would want to split any line beginning with burrito and all subsuquent lines into a file called burrito until a line with taco in it was read, I think the best way to do this would be:</p>
  
  <pre><code>for each line in $text;
     if line contains burrito
           outputfile=burrito
           line&gt;&gt;$outputfile
     elseif line contains taco
           outputfile=taco
           line&gt;&gt;$outputfile
     else
           line&gt;&gt;$outputfile
  </code></pre>
  
  <p>but I am not sure, any help would be appreciated. </p>