Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi. I have a long text file that I would like to split into several files. It can either be split at every 1004th line (not counting blank lines), or it can be split every time the line is equal to "Nrun: x", where x is some number running from 1 to lets say 20 (which occurs every 1004th line). So I want 20 new files, each with the content of the corresponding 1004 lines.
However, I already tried something like the code below, which does the work, but running this code takes a lot of time due to checking the content of every line.
set /a Nb=0
set /a Nt=0
for /f "tokens=*" %%b in (bigfile.txt) do call :sub1 %%b
goto :eof:sub1
set Line="%*"
if not %Line% equ "Nrun: %Nb%" (echo %* >> bigfile_%Nt%.txt)
if %Line% equ "Nrun: %Nb%" (set /a Nb+=1)
set /a Nt=%Nb%-1
goto :eofPlease help me create a faster code. Thanks

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |