Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Two points here:</p> <p>1- The <code>setlocal EnableDelayedExpansion</code> command is executed <em>with every line of the file</em>. This means that about 200000 times the complete environment must be copied to a new local memory area. This may cause several problems.</p> <p>2- I suggest you to start with the most basic part. How much time takes the findstr to execute? Run <code>findstr /n ^^ old-file.xml</code> alone and check this before trying to fix any other part. If this process is fast, then add a single step to it and test again until you discover the cause of the slow down. I suggest you not use pipes nor <code>for /f</code> over the execution of <code>findstr</code>, but over the file generated by a previous redirection.</p> <p><strong>EDIT</strong> <em>A faster solution</em></p> <p>There is another way to do this. You may pipe findstr output into a Batch subroutine, so the lines can be read with <code>SET /P</code> command. This method allows to process the lines entirely via delayed expansions and not via the command-line susbtitution of <code>FOR /F</code>, so the pair of <code>setlocal EnableDelayedExpansion</code> and <code>endlocal</code> commands are no longer necessary. However, if you still want to display the line number it is necessary to calculate it again.</p> <p>Also, it is faster to load the wrong dates in a variable instead of process the %tmpfile% with every line of the big file.</p> <pre><code>setlocal EnableDelayedExpansion rem load wrong dates from tmpfile set wrong-dates= for /F %%i in (%tmpfile%) do ( set wrong-dates=!wrong-dates! %%i ) echo creating findstr output, please wait... findstr /n ^^ old-file.xml &gt; findstr.txt echo :EOF&gt;&gt; findstr.txt rem start replacing wrong dates with correct date call :ProcessLines &lt; findstr.txt goto :eof </code></pre> <p>.</p> <pre><code>:ProcessLines set line=0 :read-next-line set /P read-line= rem check if the input file ends if !read-line! == :EOF goto :eof rem write progress in title bar set /A line+=1 title Processing line: %line%/%lines% for %%i in (%wrong-dates%) do ( rem replace all wrong dates with correct dates set read-line=!read-line:%%i=%correctdate%! ) rem write results to new file echo(!read-line:*:=!&gt;&gt;"Updated-file.xml" rem go back for next line goto read-next-line </code></pre> <p><strong>SECOND EDIT</strong> <em>An even faster modification</em></p> <p>Previous method may be slighlty speeded up if the loop is achieved via <code>for /L</code> command instead of via a <code>goto</code>.</p> <pre><code>:ProcessLines for /L %%l in (1,1,%lines%) do ( set /P read-line= rem write progress in title bar title Processing line: %%l/%lines% for %%i in (%wrong-dates%) do ( rem replace all wrong dates with correct dates set read-line=!read-line:%%i=%correctdate%! ) rem write results to new file echo(!read-line:*:=!&gt;&gt;"Updated-file.xml" ) </code></pre> <p>This modification also omit the :EOF comparison and the calculation of line number, so the time gain may be significative after repeated it 200000 times. If you use this method, don't forget to delete the <code>echo :EOF&gt;&gt; findstr.txt</code> line in first part.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload