title: Groovy create map from lines of text
body: <p>I have raw data that is contained in 3 separate lines. I want to build a single map record using parts of each line. I then read the next 3 lines and create the next map record and so on. All the groovy examples I've found on maps show them being created from data on a single line, or possibly i am misunderstanding the examples. Here is what the raw data looks like.</p>
  
  <pre><code>snmp v2: data result = "Local1"
  snmp v2: data result ip = "10.10.10.121"
  snmp v2: data result gal = "899"
  new
  snmp v2: data result = "Local2"
  snmp v2: data result ip = "192.168.10.2"
  snmp v2: data result gal = "7777"
  new  
  </code></pre>
  
  <p>I want to put this data into a map. In this example Local1 and Local2 would be keys and they would each have 2 associated values. I will show you my latest attempt but it is little more then a guess that failed.  </p>
  
  <pre><code>def data = RAW
  def map = [:]
  data.splitEachLine("="){
   it.each{ x -&gt;
   map.put(it[0], it[1])
  
   map.each{ k, v -&gt; println "${k}:${v}" } }}   
  </code></pre>
  
  <p>The desired output is:</p>
  
  <pre><code>[ Local1 : [ ip: "10.10.10.121", gal: "899" ], 
  Local2: [ ip: "192.168.10.2", gal: "7777" ] ]      
  </code></pre>