title: Sum values from various lines in a file
body: <p>structureA is occuring multiple times in a file and I have to sum the values of parameter1 separately under numUnitsA, numUnitsB, numUnitsC for all occurance of structureA.</p>
  
  <pre><code>structureA {
      numUnitsA {
          parameter1 = 2
      }    
      numUnitsB {
          parameter1 = 4
      }    
      numUnitsC {
          parameter1 = 3
      }    
  } 
  </code></pre>
  
  <p>I use the below to get the values but how to sum them such as :</p>
  
  <pre><code>numUnitsA parameter1=6
  numUnitsB parameter1=9
  numUnitsC parameter1=9
  </code></pre>
  
  <p>code:</p>
  
  <pre><code>while read -r line
  do
  if grep -q "parameter1" "$filename"; then
     echo $(awk 'BEGIN{FS="="}{print $2}' )
  fi
  done &lt; "$filename"
  </code></pre>