title: Convert key:value to CSV file
body: <p>I found the following bash script for converting a file with key:value information to CSV file:</p>
  
  <pre><code>awk -F ":" -v OFS="," '
  BEGIN { print "category","recommenderSubtype", "resource", "matchesPattern", "resource", "value" }
  function printline() {
  print data["category"], data["recommenderSubtype"], data["resource"], data["matchesPattern"], data["resource"], data["value"]
  }
  {data[$1] = $2}
  NF == 0 {printline(); delete data}
  END {printline()}
  ' file.yaml
  </code></pre>
  
  <p>But after executed it, it only converts the first group of data (only the first 6 rows of data), like this</p>
  
  <pre><code>category,recommenderSubtype,resource,matchesPattern,resource,value
  COST,CHANGE_MACHINE_TYPE,instance-1,f1-micro,instance-1,g1-small
  </code></pre>
  
  <p>My original file is like this (with 1000 rows and more):</p>
  
  <pre><code>category:COST
  recommenderSubtype:CHANGE_MACHINE_TYPE
  resource:portal-1
  matchesPattern:f1-micro
  resource:portal-1
  value:g1-small
  category:PERFORMANCE
  recommenderSubtype:CHANGE_MACHINE_TYPE
  resource:old-3
  matchesPattern:n1-standard-4
  resource:old-3
  value:n1-highmem-2
  </code></pre>
  
  <p>Is there any command am I missing?</p>