Hi Everyone
I Have 1 file TXT with 1000 lines of DATA. I would link use batch script to split this Text Files intro 5 Files with 200 lines each. Can You Help-me?
Thanks a lot
Batch to Split TXT Files
Moderator: DosItHelp
Re: Batch to Split TXT Files
Hi
I already posted a solution here : [Batch] Split a .txt file into a batch file ; and you can easily edit just one line in this variable : Limit_Line_Counter

I already posted a solution here : [Batch] Split a .txt file into a batch file ; and you can easily edit just one line in this variable : Limit_Line_Counter
Code: Select all
@echo off
Title A batch splitting text Script by Hackoo 2020
Color 0A
set "Limit_Line_Counter=200" REM You can modify and edit just this line
set "InputFile=%1"
If "%~x1" NEQ ".txt" Goto :Help
set "lineCounter=1"
set "filenameCounter=1"
SetLocal EnableDelayedExpansion
@for %%a in (%InputFile%) do (
set "name=%%~na"
set "extension=%%~xa"
@for /L %%i in (1,1,100) Do (
If Exist "!name!%%i!extension!" Del "!name!%%i!extension!"
)
)
@for /f "tokens=*" %%a in (%InputFile%) do (
set "splitFile=!name!!filenameCounter!!extension!"
set /a lineCounter+=1
if !lineCounter! GTR !Limit_Line_Counter! (
set /a filenameCounter+=1
set lineCounter=1
echo Created !splitFile!
)
echo %%a>>!splitFile!
)
Timeout /T 3 /nobreak>nul & Exit
::------------------------------------------------------------------
:Help
Color 0C & Mode 80,3
echo(
echo Usage : Drag and Drop a txt file over this script:"%~nx0"
Timeout /T 5 /nobreak>nul & Exit
::------------------------------------------------------------------