title: Batch file doesn't insert text from another file
body: <p>I am working in Windows 10 and I have text files resulting from another process that I want to edit using a batch file. I've shortened the example, File-1 (shown below with line numbers) for this post. They are all formatted this way, but much longer and with more sections:</p>
  <pre><code>1 Album 1 - 1982,,,      
  2 ('Song 1'),      
  3 ('Song 2'),      
  4 |===================|      
  5 Album 2 - 1978,,,      
  6 ('Song 1'),      
  7 ('Song 2'),    
  </code></pre>
  <p>After each line with a string of 3 commas (lines 1 and 5) I want to insert two new lines of text from File-2 before the existing lines in File-1 (lines 2 and 6).</p>
  <p>The two lines in File-2 to insert are:</p>
  <pre><code>NEW LINE 1
  NEW LINE 2
  </code></pre>
  <p>The desired output would then be:</p>
  <pre><code>1 Album 1 - 1982,,,      
  2 NEW LINE 1
  3 NEW LINE 2
  4 ('Song 1'),      
  5 ('Song 2'),      
  6 |===================|      
  7 Album 2 - 1978,,,      
  8 NEW LINE 1
  9 NEW LINE 2
  10 ('Song 1'),      
  11 ('Song 2'),    
  </code></pre>
  <p>The closest I've come so far as an experiment is a batch file (that I found and adapted) that finds the 3 commas and replaces them with 3 dots.</p>
  <pre><code>@echo off &amp;setlocal
  set &quot;search=,,,&quot;
  set &quot;replace=...&quot;
  (for /f &quot;delims=&quot; %%i in (a.txt) do (
      set &quot;word=%%i&quot;
      setlocal enabledelayedexpansion
      set &quot;word=!word:%search%=%replace%!&quot;
      echo(!word!
      endlocal
      )
  )
  </code></pre>
  <p>Output of the adapted batch file to the screen:</p>
  <pre><code>1 Album 1 - 1982...      
  2 ('Song 1'),      
  3 ('Song 2'),      
  4 |===================|      
  5 Album 2 - 1978...      
  6 ('Song 1'),      
  7 ('Song 2'),    
  </code></pre>
  <p>I don't need to change the commas to dots (that was just a test to see if I could make the batch file stop and do something at each instance of a unique string).</p>
  <p>My dilemma is that I have searched for hours and can't find how to insert File-2 text in the two proper places of File-1. I've found many explanations on how to insert another file's text at one point or at the end of a first file (using the &quot;type&quot; command), but not at more than one specific point found from the search. Also, File-2 text might be more than two lines in the future, so that is why I want to use an external file to hold it.</p>
  <p>All I really want to do right now is:</p>
  <ol>
  <li>Find a known string (3 commas).</li>
  <li>Read boilerplate text from a text file and insert it below the lines with the found strings, into the the file sitting in the batch file memory.</li>
  </ol>
  <p>For testing, I am echoing this to the screen, but once I am able to get the right output, I can edit the batch file to redirect output to a file. I know there are easier ways of doing this using python or C, but it seems it should be easy to do this way with a small correction.</p>
  <p><strong>UPDATE</strong></p>
  <p>I corrected my batch file per @aschipfl, and made new input files for easier debugging.</p>
  <p>a.txt:</p>
  <pre><code>A LINE 1,,,
  A LINE 2
  </code></pre>
  <p>b.txt:</p>
  <pre><code>B LINE 1
  B LINE 2
  </code></pre>
  <p>I methodically tried three versions of the FIND statement starting with the @aschipfl original but there is no interaction with b.txt.</p>
  <pre><code>if not &quot;!word!&quot;==&quot;!word:%search%=!&quot; find /V &quot;,,,&quot; &lt; &quot;!infile2!&quot; 
  if not &quot;!word!&quot;==&quot;!word:%search%=!&quot; &lt; &quot;!infile2!&quot;  find /V &quot;,,,&quot;
  if not &quot;!word!&quot;==&quot;!word:%search%=!&quot; find /V &quot;,,,&quot; type &quot;!infile2!&quot;
  </code></pre>
  <p>The fourth combination <strong>does</strong> interact with b.txt as shown below it.</p>
  <pre><code>if not &quot;!word!&quot;==&quot;!word:%search%=!&quot; type &quot;!infile2!&quot;  find /V &quot;,,,&quot;
  </code></pre>
  <pre><code>C:\Users\Pete\Documents\test&gt;test.bat
  A LINE 1,,,
  
  b.txt
  
  
  B LINE 1
  B LINE 2The system cannot find the file specified.
  Error occurred while processing: find.
  The system cannot find the file specified.
  Error occurred while processing: /V.
  The system cannot find the file specified.
  Error occurred while processing: ,,,.
  A LINE 2
  
  C:\Users\Pete\Documents\test&gt;
  </code></pre>
  <p>Now, the batch file reads both lines of both input files but with errors as shown (complete with blank lines, copied directly from screen).</p>