I was required to split one large file to multiple file based on line number. Here in following script you will see 200k lines is going to each new split file from large original file. It will create up to 199 new split files. In my case, I had 3 files as my total records were little bit more than 400k.

@ECHO OFF
SETLOCAL
SET “sourcedir=C:\MDM\other_files\BucketAnalysis\data”
SET /a fcount=199
SET /a llimit=200000
SET /a lcount=%llimit%
FOR /f “usebackqdelims=” %%a IN (“%sourcedir%\SampleDataLoad.txt”) DO (
CALL :select
>>”%sourcedir%\file$$.txt” ECHO(%%a
)
SET /a lcount=%llimit%
:select
SET /a lcount+=1
IF %lcount% lss %llimit% GOTO :EOF
SET /a lcount=0
SET /a fcount+=1
MOVE /y “%sourcedir%\file$$.txt” “%sourcedir%\file%fcount:~-2%.txt” >NUL 2>nul
GOTO :EOF

Ref: http://stackoverflow.com/questions/25249516/split-text-file-into-smaller-multiple-text-file-using-command-line

Advertisements