Solved Split text file every n lines and save separate text files

September 25, 2016 at 21:49:46
Specs: Windows 7
Hi, anyone can help me? I need to export n lines, every n lines, from a text file and save them into separate text files. For example if I have a file with 50 lines and I need to split it into 5 files with 10 lines each, how I can do it with batch?

See More: Split text file every n lines and save separate text files

Reply ↓  Report •


#1
September 26, 2016 at 04:15:15
✔ Best Answer
:: get 10 LINE chunks into separate files
::
::
::
::====== script starts here ===============
::
:: 10LINES.bat 2016-09-26 17:41:34.51
@echo off & setLocal enableDELAYedeXpansioN

if exist OUT* del OUT*
set/a N=-1
set/a F=0

:main
for /f "tokens=* delims= " %%a in (myfile) do (
set/a N+=1 & if !N! equ 10 set/a N=0 && set/a F+=1
>> OUT!F! echo.%%a
)
goto :eof
::====== script ends here =================

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#2
September 26, 2016 at 14:51:31
I've changed the number 10 of the example with one that i need, also i've changed the name of the output (out), and it worked perfectly, thanks a lot!

Reply ↓  Report •

Related Solutions


Ask Question