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
abc1-xx
xyz2-xx
xyz3-xx
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
It may help - it will split the text into separate files
abc1.txtxyz2.txtxyz3.txt
@echo off for /f "tokens=1,* delims=-" %%a in ('type "file.txt"') do ( >>"%%a.txt" echo(%%a-%%b ) pause
Use the cgwin SPLIT command.
Samples:
-split file every 500 lines:
split -l 500 [filename.ext]
Read more: split --help