Computing.Net > Forums > Windows XP > Batch file to split a text file?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file to split a text file?

Reply to Message Icon

Name: CMDnewbie
Date: July 14, 2009 at 03:10:04 Pacific
OS: Windows XP
Subcategory: General
Comment:

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 :eof

Please help me create a faster code. Thanks



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Batch file to split a text file?

How to make a text homepage? www.computing.net/answers/windows-xp/how-to-make-a-text-homepage/86868.html

Batch file to edit text file www.computing.net/answers/windows-xp/batch-file-to-edit-text-file/156973.html

Batch file parsing a text file www.computing.net/answers/windows-xp/batch-file-parsing-a-text-file/174226.html