title: How to find and replace string based on start and end position
body: <p>I already search the net but I was not able to find any useful articles.</p>
  
  <p>Here's my scenario:</p>
  
  <p>For example I have a file that contains:</p>
  
  <pre><code>AAAA            1111
  BBBB            2222
  CCCC            3333
  </code></pre>
  
  <p>Assuming that the 1111, 2222 and 3333 are on position 20-23. I want to have a file that was being called that is being used to determine the line pattern, start position, end position and the string to be use as a replacement.</p>
  
  <p>Example the file name is replace.txt that contains the following:</p>
  
  <pre><code>BBBB    20    23     7777
  </code></pre>
  
  <p>Now, THis file will be called by the batch file that will do this step:</p>
  
  <ol>
  <li>Find line that starts with BBBB, </li>
  <li>Replace the position 20-23 which is 2222 by the 7777 indicated in the replace.txt file.</li>
  </ol>
  
  <p>I already have this code that iterates in every occurrences found in replace.txt file.</p>
  
  <pre><code>for /f "tokens=1-4" %%s in (replace.txt) do (
      Type "C:\user\linefeed\%%a.in.tmp"  | C:\user\bat\repl.bat "\%%s" "%%t" X &gt; "C:\user\linefeed\%%a.out.tmp"
      move /y "C:\user\linefeed\%%a.out.tmp" "C:\user\linefeed\%%a.in.tmp"
    )
    move "C:\user\linefeed\%%a.in.tmp" "C:\user\out\%%a"
  </code></pre>
  
  <p>Now, how will I implement the above scenario? That finds first the line pattern, the the start and end position, any string found in the indicated start and end position will be replaced by the token 4 of replace.txt.</p>
  
  <p>Expected output must be:</p>
  
  <pre><code>AAAA            1111
  BBBB            7777
  CCCC            3333
  </code></pre>