Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>@ECHO OFF SETLOCAL :temploop (SET tempfile="%temp%\temp%random%.#$#") IF EXIST %tempfile% GOTO temploop (FOR /f "delims=" %%x IN (myfile.ini) DO ( &gt;%tempfile% ECHO %%x FINDSTR /b "Extmgr_Addins=" &lt;%tempfile% &gt;NUL IF ERRORLEVEL 1 (ECHO.%%x) ELSE ( FIND "mc" &lt;%tempfile% &gt;NUL IF ERRORLEVEL 1 (ECHO %%x,mc) ELSE (ECHO %%x) ) ) )&gt;newfile.ini DEL %tempfile% ECHO ==== original file ===== type myfile.ini ECHO ==== modified file ===== type newfile.ini ECHO ==== differences ===== FC myfile.ini newfile.ini ECHO ==== end of report ===== GOTO :eof </code></pre> <p>Result:</p> <pre><code>tempfile="c:\temp\temp8291.#$#" ==== original file ===== notthisline Extmgr_Addins=notargetstring Extmgr_Addins=mchastargetstring Extmgr_Addins=hastargetatendmc Extmgr_Addins=notbeginsnotargetstring Extmgr_Addins=notbeginsmchastargetstring Extmgr_Addins=notbeginshastargetatendmc mcinthisline thislinehasmctoo andat the end mc mc and Extmgr_Addins= Extmgr_Addins=finally !@#$%^&amp;*()_+|\=-0&lt;&gt;,./?:;'[]{}" Extmgr_Addins=mc finally !@#$%^&amp;*()_+|\=-0&lt;&gt;,./?:;'[]{}" ==== modified file ===== notthisline Extmgr_Addins=notargetstring,mc Extmgr_Addins=mchastargetstring Extmgr_Addins=hastargetatendmc Extmgr_Addins=notbeginsnotargetstring Extmgr_Addins=notbeginsmchastargetstring Extmgr_Addins=notbeginshastargetatendmc mcinthisline thislinehasmctoo andat the end mc mc and Extmgr_Addins= Extmgr_Addins=finally !@#$%^&amp;*()_+|\=-0&lt;&gt;,./?:;'[]{}",mc Extmgr_Addins=mc finally !@#$%^&amp;*()_+|\=-0&lt;&gt;,./?:;'[]{}" ==== differences ===== Comparing files myfile.ini and NEWFILE.INI ***** myfile.ini notthisline Extmgr_Addins=notargetstring Extmgr_Addins=mchastargetstring ***** NEWFILE.INI notthisline Extmgr_Addins=notargetstring,mc Extmgr_Addins=mchastargetstring ***** ***** myfile.ini mc and Extmgr_Addins= Extmgr_Addins=finally !@#$%^&amp;*()_+|\=-0&lt;&gt;,./?:;'[]{}" Extmgr_Addins=mc finally !@#$%^&amp;*()_+|\=-0&lt;&gt;,./?:;'[]{}" ***** NEWFILE.INI mc and Extmgr_Addins= Extmgr_Addins=finally !@#$%^&amp;*()_+|\=-0&lt;&gt;,./?:;'[]{}",mc Extmgr_Addins=mc finally !@#$%^&amp;*()_+|\=-0&lt;&gt;,./?:;'[]{}" ***** ==== end of report ===== </code></pre> <p>The first few lines deal with establishing a valid temporary filename.</p> <p>We then </p> <ol> <li>Read a line</li> <li>dump it into the tempfile</li> <li>Check for the line beginning with the target string</li> <li>If not-found (errorlevel 1) ECHO the line</li> <li>If found (Not errorlevel 1, so errorlevel is 0)</li> </ol> <ul><li>Check for presence of "mc"</li> <li>if not found, output line with ",mc" appended else just output the line</li> </ul> <p>Then delete the tempfile and show a report: The original MYFILE.INI used The output NEWFILE.INI and the differences between them.</p> <p>Writing the line-under-examination to the tempfile means that awkward characters like <code>&lt;</code> and <code>&gt;</code> which are redirectors in batch are dealt with properly. The normal method would be to <code>ECHO %%x|findstr...</code> but <code>&gt;</code> gets stuck in the pipe and leaks out an error message.</p> <p>About the only problem is that empty lines and possibly lines beginning ';' will be deleted from the output, but lines consisting soleley of spaces will be preserved...</p>
 

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