title: How to use linux csplit to chop up massive XML file?
body: <p>I have a gigantic (4GB) XML file that I am currently breaking into chunks with linux "split" function (every 25,000 lines - not by bytes).  This usually works great (I end up with about 50 files), except some of the data descriptions have line breaks, and so frequently the chunk files do not have the proper closing tags - and my parser chokes halfway through processing.</p>
  
  <p><strong>Example file:</strong>  (note: normally each "listing" xml node is supposed to be on its own line)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;listings&gt;
  &lt;listing&gt;&lt;date&gt;2009-09-22&lt;/date&gt;&lt;desc&gt;This is a description WITHOUT line breaks and works fine with split&lt;/desc&gt;&lt;more_tags&gt;stuff&lt;/more_tags&gt;&lt;/listing&gt;
  &lt;listing&gt;&lt;date&gt;2009-09-22&lt;/date&gt;&lt;desc&gt;This is a really
  annoying description field
  WITH line breaks 
  that screw the split function&lt;/desc&gt;&lt;more_tags&gt;stuff&lt;/more_tags&gt;&lt;/listing&gt;
  &lt;/listings&gt;
  </code></pre>
  
  <p>Then sometimes my split ends up like</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;listings&gt;
  &lt;listing&gt;&lt;date&gt;2009-09-22&lt;/date&gt;&lt;desc&gt;This is a description WITHOUT line breaks and works fine with split&lt;/desc&gt;&lt;more_tags&gt;stuff&lt;/more_tags&gt;&lt;/listing&gt;
  &lt;listing&gt;&lt;date&gt;2009-09-22&lt;/date&gt;&lt;desc&gt;This is a really
  annoying description field
  WITH line breaks ... 
  EOF
  </code></pre>
  
  <p>So - I have been reading about "csplit" and it sounds like it might work to solve this issue.  I cant seem to get the regular expression right...</p>
  
  <p>Basically I want the same output of ~50ish files</p>
  
  <p>Something like:</p>
  
  <pre><code>*csplit -k myfile.xml '/&lt;/listing&gt;/' 25000 {50}
  </code></pre>
  
  <p>Any help would be great
  Thanks!</p>