title: Extract multiple occurrences on the same line using sed/regex
body: <p>I am trying to loop through each line in a file and find and extract letters that start with <code>${</code> and end with <code>}</code>. So as the final output I am expecting only <code>SOLDIR</code> and <code>TEMP</code>(from <code>inputfile.sh</code>). </p>
  
  <p>I have tried using the following script but it seems it matches and extracts only the second occurrence of the pattern <code>TEMP</code>. I also tried adding <code>g</code> at the end but it doesn't help. Could anybody please let me know how to match and extract both/multiple occurrences on the same line ?</p>
  
  <p><em>inputfile.sh:</em></p>
  
  <pre><code>.  
  .  
  SOLPORT=\`grep -A 4 '\[LocalDB\]' \${SOLDIR}/solidhac.ini | grep \${TEMP} | awk '{print $2}'\`  
  .  
  .  
  </code></pre>
  
  <p><em>script.sh:</em>  </p>
  
  <pre><code>infile='inputfile.sh'  
  while read line ; do    
    echo $line | sed 's%.*${\([^}]*\)}.*%\1%g'  
  done &lt; "$infile"  
  </code></pre>