The following script shows more advanced split file technique, where FOR function loops through a list of files in a directory, and each file content is piped to FINDSTR that looks for a string containing substring
var preceded by undefined number of spaces and superseded by any extra text. Once found, the searched file is replaced with a new one that contains only the text portion above the search string.
@echo off setlocal enabledelayedexpansion pushd "%temp%\Test" for %%G in ("*.txt") do (set "break=" (for /f "tokens=*" %%H in (%%~G) do ( if not defined break ( echo %%H | findstr /r /b /c:"[ ]*var.*" >nul && set break=TRUE || echo %%H ) )) >> %%~nG_mod.txt del %%~G & ren %%~nG_mod.txt %%G ) popd exit /b
Note, how setting
break=TRUE allows to exit FOR loop from the file searched, once the 1st occurrence of the search string is found.