title: Batch file replace string in csv with list from another file
body: <p>i need to replace the numbers in a csv-column with the help of a list in another file. I just started to learn about batch processing and found a script that i adjusted to my needs. </p>
  
  <p>This is the code i use and to solve this problem first, i just take the 3rd column, exchange the numbers and write the old one and the new one into a new file:</p>
  
  <pre class="lang-bat prettyprint-override"><code>@echo off &amp; setlocal enabledelayedexpansion
  
  set "Datei=lohn_prod.csv"
  set "MA=Mitarbeiter.csv"
  set "Ziel=eGecko.csv"
  
  set "t=%temp%\text.tmp"
  if exist "%t%" del "%t%"
  for /f "tokens=3 delims=;" %%i in ('findstr /n $ "%Datei%"') do set "Line=%%i" &amp; call :ProcessLine
  move "%t%" "%Ziel%"
  goto :eof
  
  :ProcessLine
  for /f "tokens=1 delims=" %%i in ("%Line%") do set "L=%%i"
  if not defined L &gt;&gt;"%t%" echo\&amp; goto :eof
  echo %L%
  for /f "usebackq tokens=1,2 delims=;" %%i in ("%MA%") do set "L=!L:%%i=%%j!"
  &gt;&gt;"%t%" echo %Line%, %L%
  goto :eof
  </code></pre>
  
  <p>The old csv (<em>lohn_prod.csv</em>) looks like this:</p>
  
  <pre><code>15;01.09.2016;105;160,25;1;2100;210;
  15;01.09.2016;105;40;1;;217;
  15;01.09.2016;105;5;72;;;
  15;01.09.2016;107;184;1;2213;210;
  15;01.09.2016;107;7,25;1;;213;
  15;01.09.2016;107;16;1;;216;
  15;01.09.2016;108;241,25;1;3200;210;
  15;01.09.2016;108;21,25;1;;222;
  15;01.09.2016;113;174,75;1;2111;210;
  15;01.09.2016;113;16;1;;216;
  ...
  </code></pre>
  
  <p>The other file (<em>Mitarbeiter.csv</em>) i use to replace the 3rd column looks like this:</p>
  
  <pre><code>105;40200
  107;40201
  108;40202
  113;40203
  115;40204
  170;40219
  172;40220
  195;40222
  197;40223
  198;40224
  199;40225
  200;40226
  201;40227
  220;40228
  235;40229
  240;40230
  ...
  </code></pre>
  
  <p>The problem though is, that it seems to iterate through L again from the beginning on each loop, because i get this result:</p>
  
  <pre><code>105, 4040226
  105, 4040226
  105, 4040226
  107, 4040227
  107, 4040227
  107, 4040227
  108, 40202
  108, 40202
  113, 40203
  113, 40203
  115, 40204
  170, 40219
  170, 40219
  172, 4040228
  172, 4040228
  172, 4040228
  185, 40221
  185, 40221
  185, 40221
  ...
  </code></pre>
  
  <p>As it seems, it first finds 105 and replaces it with 40200, then on the next loop it finds the 200 in 40200 and replaces it with 40226, same with 107 and 201 in 40201. Since there is no number 202 in <em>Mitarbeiter.csv</em>, 108 gets correctly replaced with 40202.</p>