Split a text file into multiple files using a windowed batch script

I need to split one text file into several files using windows script package, can anyone ignite me?

sample text file:

abc1-10
abc1-11
abc1-12
xyz2-01
xyz2-02
xyz3-01
xyz3-02

in this case it should be divided into 3 files, the lines consist first abc1-xx, the second consists of xyz2-xxand xyz3-xxgo to the last

+4
source share
3 answers

You can use a batch file, but why not just use the FINDSTR command ?

findstr /R "^abc1-" sample.txt > file1.txt
findstr /R "^xyz2-" sample.txt > file2.txt
findstr /R "^xyz3-" sample.txt > file3.txt
+5
source

It may help - it will split the text into separate files

abc1.txt
xyz2.txt
xyz3.txt

@echo off
for /f "tokens=1,* delims=-" %%a in ('type "file.txt"') do (
>>"%%a.txt" echo(%%a-%%b
)
pause
+5

Use the cgwin SPLIT command.

Samples:

-split file every 500 lines:

      split -l 500 [filename.ext]

Read more: split --help

+4
source

All Articles