title: Count substitutes per line
body: <p>I have a (BIG) file containing lines like:</p>
  
  <pre><code>foobar {} foo{} bar{} foobar{}{}
  foo {} foodfg{} bar{} foogfdbar{}
  line without brackets
  foobdgar {} fdfgoo{} bga foodfbar{}{}
  fdfgoobar {} fdfoo dbar{} fooddbar
  </code></pre>
  
  <p>now I want to replace every {} with {$MATCH_COUNT} <strong>for each line seperately</strong><br>
  Meaning the output should look like this:</p>
  
  <pre><code>foobar {0} foo{1} bar{2} foobar{3}{4}
  foo {0} foodfg{1} bar{2} foogfdbar{3}
  line without brackets
  foobdgar {0} fdfgoo{1} bga foodfbar{2}{3}
  fdfgoobar {0} fdfoo dbar{1} fooddbar
  </code></pre>
  
  <p>How can I do this in perl or awk? I am not an expert in these languages so I would highly appreciate it if you could explain shortly what the code is doing.</p>
  
  <p>My solutions so far that do not work like I intended:</p>
  
  <p>Perl:   </p>
  
  <pre><code>cat test.properties | perl -e 'while(&lt;&gt;){ $c=0; while(/{}/g){print "{$c}"; $c++} print "\n"}'
  </code></pre>
  
  <p>(replaces it like i want but doesn't keep the unmatched stuff)</p>
  
  <p>Awk:  </p>
  
  <pre><code>cat test.properties | awk '{ print "{" gsub(/{}/, "") "}" }'  
  </code></pre>
  
  <p>(replaces every line with a complete count - not what I want)</p>