0

I am looking for a simple batch script that split my text file into two files. The text file is separated by with

============================================================================

Text file looks like this:

test
test1
test2
test5
test
test1
test2
test5
============================================================================
test
test1
test2
test5
test
test1   
Endoro
  • 37,015
  • 8
  • 50
  • 63
user1809753
  • 165
  • 3
  • 12

2 Answers2

3

try this:

@echo off&setlocal
set "file=file.txt"
for /f "delims=[]" %%i in ('^<"%file%" find /n "="') do set "split=%%i"
(for /f "tokens=1*delims=[]" %%i in ('^<"%file%" find /n /v ""') do if %%i lss %split% echo(%%j)>"%file%.new1"
<"%file%">"%file%.new2" more +%split%
type "%file%.new?"

..output is:

file.txt.new1


test
test1
test2
test5
test
test1
test2
test5

file.txt.new2


test
test1
test2
test5
test
test1
Endoro
  • 37,015
  • 8
  • 50
  • 63
2
@echo off
set /p file=FILE TO PROCESS : 
del /q /f out.file*
setlocal enableDelayedExpansion
set out_file_counter=1
for /f "usebackq delims=" %%L in ("%file%") do (
 set line=%%L
 if "!line:~0,5!" equ "=====" (
    set /a out_file_counter=out_file_counter+1

 ) else (
   echo !line!>>out.file.!out_file_counter!
  )
)
endlocal
npocmaka
  • 55,367
  • 18
  • 148
  • 187