title: Awk replace after loop
body: <p>I want to override the child_value with the parent_value using awk. The solution must be generic applicable for larger data sources. The parent-record is defined by $1==$2.</p>
  
  <p>This is my input file (format: ID;PARENT_ID;VALUE):</p>
  
  <pre><code>10;20;child_value
  20;20;parent_value
  </code></pre>
  
  <p>This is the result I want:</p>
  
  <pre><code>10;20;parent_value
  20;20;parent_value
  </code></pre>
  
  <p>This is my current approach:</p>
  
  <pre><code>  awk -F\;
          BEGIN {
              OFS = FS
          }
          {
              if ($1 == $2) {
                  mapping[$1] = $3
              }
              all[$1]=$0
          } 
          END {
              for (i in all) {
                if (i[$3] == 'child_value') {
                   i[$3] = mapping[i]
                }
                print i
              }
          }
      ' file.in
  </code></pre>
  
  <p>Needless to say, that it doesn't work like that ;-) Anyone can help?</p>