All Posts

FileSplitter Tool - Splitting data file

S

By Suhas Das

Author

2 views

update the following lines:

set "inputFile=C:\path\to\your\input.txt"
set "outputFolder=C:\path\to\output"
set "linesPerFile=1000"

and here is the bat file:

@echo off
setlocal

:: Set variables
set "inputFile=C:\path\to\your\input.txt"
set "outputFolder=C:\path\to\output"
set "linesPerFile=1000"

:: Create output directory if it doesn't exist
if not exist "%outputFolder%" (
mkdir "%outputFolder%"
)

:: Run PowerShell to split the file
powershell -Command ^
"$inputFile = '%inputFile%';" ^
"$outputFolder = '%outputFolder%\';" ^
"$linesPerFile = %linesPerFile%;" ^
"$i = 0;" ^
"Get-Content $inputFile -ReadCount $linesPerFile | ForEach-Object {" ^
"$i++;" ^
"$outFile = '{0}part_{1}.txt' -f $outputFolder, $i;" ^
"$_ | Set-Content $outFile" ^
"}"

echo Done!
pause

0 Comments

Leave a Comment

Your email will not be published. Comments are subject to moderation.