title: CMD script to find and replace a part of found line in file
body: <p>I need to find all lines in myfile.txt containing word 'MyWord', and then replace a part of this string next way:</p>
  
  <p>Original line: </p>
  
  <pre><code> ...,31-01-2012,00,some_words_and_symbols_and_digits,MyWord,...
  </code></pre>
  
  <p>After replace: </p>
  
  <pre><code> ...,31-01-2012,01,some_words_and_symbols_and_digits,MyWord,...
  </code></pre>
  
  <p>Please, help me to write this cmd script!</p>
  
  <p>OK.. I have next code:</p>
  
  <pre><code>@echo off
  set code=MyWord
  set req=new request
  
  FOR /F "usebackq delims=, tokens=1,2,3,4,5,6,7,8,9*" %%a in (MyFile.txt) do (
  
  IF %%h==%code% (
      SET tempstr=%%a,%%b,%%c,%%d,60,%%f,%%g,%%h,%%i
      ) ELSE (
      SET tempstr=%%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,%%i
      ) 
  
  IF %%a==%req% (
      SET echo %%a &gt;&gt; new.strings
      ) ELSE (
      echo %tempstr% &gt;&gt; new.strings
      )
  
  )
  @echo on
  </code></pre>
  
  <p>And I have in my file something like:</p>
  
  <pre><code> new request
   ...,31-01-2012,01,some_words_and_symbols_and_digits,MyWord,...
   new request
   ...,30-11-2011,01,some_words_and_symbols_and_digits,OtherWords,...
  </code></pre>
  
  <p>But then I have error:</p>
  
  <pre><code>ELSE was unexpected at this time.
  </code></pre>
  
  <p>And If I'm trying simple next in the end</p>
  
  <pre><code>IF %%a==%req% SET tempstr=%%a
  echo %tempstr% &gt;&gt; new.strings
  </code></pre>
  
  <p>Then I have only one last row instead of other else</p>