title: Breaking text file into multiple files mid-line
body: <p>I am receiving text files that have a series of messages in them.  I need to break these files into separate text files.  The files I receive look like this:</p>
  
  <pre><code>{1:data1}{2:data1}{3:{data1}}{4:
  data1
  data1
  data1
  data1 data data data
  data1 data data data
  data1
  data1
  -}{1:data2}{2:data2}{3:{data2}}{4:
  data2
  data2 data data data
  data2
  data2 data data data
  data2
  -}{1:data3}{2:data3}{3:{data3}}{4:
  data3
  data3 data data data
  data3
  data3
  data3
  -}{1:data4}{2:data4}{3:{data4}}{4:
  data4
  data4
  data4
  data4
  data4 data data data
  data4
  data4
  data4 data data data
  data4
  data4 data data data
  data4
  -}{1:data5}{2:data5}{3:{data5}}{4:
  data5
  data5
  -}
  </code></pre>
  
  <p>I need to break the initial file into separate text files placed within the same folder at the curly brackets before the 1.  The text files produced as a result should end up looking like this:</p>
  
  <pre><code>{1:data1}{2:data1}{3:{data1}}{4:
  data1
  data1 data data data
  data1
  data1 data data data
  data1
  data1
  data1
  -}
  </code></pre>
  
  <p>There can be a dynamic number of messages in each text file.  I have found the following code and tweaked it but am having trouble getting it to do what I want.  Any help would be greatly appreciated.</p>
  
  <pre><code>@ECHO OFF
  SETLOCAL ENABLEDELAYEDEXPANSION
  SET /a incnum=0
  SET "searchstring={1:"
  SET "found="
  FOR /f "delims=" %%a IN (msg1.txt) DO (
   ECHO("%%a"|FIND "%searchstring%" &gt;NUL
   IF NOT ERRORLEVEL 1 (SET found=Y&amp;set/a incnum+=1)
   IF DEFINED found &gt;&gt;"file!incnum!" ECHO(%%a
  )
  
  GOTO :EOF
  PAUSE
  </code></pre>