Split Single Column into many based on term that varies
<p>I've searched questions that have already been asked and couldn't find something that matched for what I'm trying to solve.</p>

<p>I am on a Mac, using terminal. I would like this to run as part of another script written in bash.</p>

<p>I have a CSV file that has a single column. Under each "header" will contain different numbers of devices depending on the output. The headers (SerialNumber, DeviceName, PurchaseDate) will always be constant.</p>

<p>SerialNumbers<br>
A1B2C3D4E5F6<br>
SASIUWOI9828<br>
I3I6K36H78SK<br>
DeviceName<br>
This one has a short name<br>
This one has a long name<br>
This one has a medium name<br>
PurchaseDate<br>
2016-02-19<br>
2016-02-01<br>
2016-02-12<br></p>

<p>Desired output</p>

<p>SerialNumbers,DeviceName,PurchaseDate<br>
A1B2C3D4E5F6,This one has a short name, 2016-02-19<br>
SASIUWOI9828,This one has a long name,2016-02-01 <br>
I3I6K36H78SK,This one has a medium name,2016-02-12 <br></p>

<p>Here is my source file, if it helps</p>

<p><a href="https://www.dropbox.com/s/wapjqbi1v3oah3p/tobecorrected.csv?dl=0" rel="nofollow">https://www.dropbox.com/s/wapjqbi1v3oah3p/tobecorrected.csv?dl=0</a></p>