title: SED or AWK replace all with patterns from another file
body: <p>I am trying to do pattern replacement using SED script but its not working properly <br></p>
  
  <p><strong>sample_content.txt</strong> <br></p>
  
  <pre><code>288Y2RZDBPX1000000001dhana
  JP2F64EI1000000002d
  EU9V3IXI1000000003dfg1000000001dfdfds
  XATSSSSFOO4dhanaUXIBB7TF71000000004adf
  10Q1W4ZEAV18LXNPSPGRTTIDHBN1000000005egw
  </code></pre>
  
  <p>patterns.txt</p>
  
  <pre><code>1000000001 9000000003
  1000000002 2000000001
  1000000003 3000000001
  1000000004 4000000001
  1000000005 5000000001
  </code></pre>
  
  <p><strong>Expected output</strong></p>
  
  <pre><code>288Y2RZDBPX9000000003dhana
  JP2F64EI2000000001d
  EU9V3IXI3000000001dfg9000000003dfdfds
  XATSSSSFOO4dhanaUXIBB7TF74000000001adf
  10Q1W4ZEAV18LXNPSPGRTTIDHBN5000000001egw
  </code></pre>
  
  <p>I am able to do with single SED replacement like <br></p>
  
  <pre><code>sed  's/1000000001/1000000003/g' sample_content.txt
  </code></pre>
  
  <p><strong>Note:</strong></p>
  
  <ul>
  <li>Matching pattern is not in fixed position. </li>
  <li>Single line may have multiple matching value to replace in sample_content.txt</li>
  <li>Sample_content.txt and patterns.txt has > 1 Million records</li>
  </ul>
  
  <p><strong>File attachment link:</strong> <a href="https://drive.google.com/open?id=1dVzivKMirEQU3yk9KfPM6iE7tTzVRdt_" rel="noreferrer">https://drive.google.com/open?id=1dVzivKMirEQU3yk9KfPM6iE7tTzVRdt_</a></p>
  
  <p>Could anyone suggest how can achieve this without affecting performance?</p>
  
  <p><strong>Updated on 11-Feb-2018</strong></p>
  
  <p>After analyzing the real file I just got a hint that there is a <strong>grade</strong> value at the <strong>30 and 31th position</strong>. Which helps where and all we need to apply replacement. <br>
  If <strong>grade AB</strong> then replace the 10 digit phone number at <strong>41-50 and 101-110</strong> <br>
  If <strong>grade BC</strong> then replace the 10 digit phone number at <strong>11-20, 61-70 and 151-160</strong><br>
  If <strong>grade DE</strong> then replace the 10 digit phone number at <strong>1-10, 71-80, 151-160 and 181-190</strong> <br></p>
  
  <p>Like this I am seeing <strong>50 unique grades</strong> for <strong>2 Million</strong> sample records.</p>
  
  <pre><code>{   grade=substr($0,110,2)} // identify grade
  { 
      if (grade == "AB") {
          print substr($0,41,10) ORS substr($0,101,10)
      } else if(RT == "BC"){
          print substr($0,11,10) ORS substr($0,61,10) ORS substr($0,151,10) 
      }
  
      like wise 50 coiditions
  }
  </code></pre>
  
  <p>May I know, whether this approach is advisable or anyother better approach?</p>