title: Batch-File: Find string in a file and add text after
body: <p>I generally use the <code>echo</code> method for writing "text" to an <code>HTML</code>-file by using:</p>
  
  <pre><code>  echo. &gt;&gt; "C:\Users\Me\Desktop\test.html"
    echo  ^&lt;div^&gt;TestDIV^&lt;/div^&gt; &gt;&gt; "C:\Users\Me\Desktop\test.html"
  </code></pre>
  
  <p>I've experienced, that <code>echo</code> always writes the additional lines to the end of the target file.</p>
  
  <p>But what if my target file (<strong>test.html</strong>) already has a structure like:</p>
  
  <pre><code>&lt;div id="wrapperDIV"&gt;
      &lt;div id="DIVcontent1"&gt;DIV 1&lt;/div&gt;
      &lt;div id="DIVcontent2"&gt;DIV 2&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and I want to write the additional lines within this existing structure, for example right after: </p>
  
  <pre><code>&lt;div id="DIVcontent1"&gt;DIV 1&lt;/div&gt;
  </code></pre>
  
  <p>I have tried to set up a script for this, but so far I couldn't make it running. (It seems to fail in the <code>for</code>-loop)</p>
  
  <pre><code>set DIVInput=^&lt;div^&gt;TestDIV^&lt;/div^&gt;
  
  set inputfile=C:\Users\Me\Desktop\test.html
  
  (for /f usebackq^ delims^=^ eol^=  %%a in ("%inputfile%") do (
  
     if "%%~a"=="DIV 1^&lt;/div^&gt;" call echo %DIVInput%
     echo %%a 
  ))&gt;&gt;"%inputfile%"
  
  pause
  </code></pre>