Page 1 of 1
Batch script to split a file into 4 files
Posted: 15 Jun 2009 07:23
by ramesh
hi,
i need a batch script to spilt a single file into 4 files.
I would really appreciate if anyone can anyone help me with that?
Thanks,
Ramesh
Posted: 15 Jun 2009 08:10
by RElliott63
Ramesh,
You have to have some sort of criteria on breaking the file down. Number of records? Key field information? They way the sun sets over Bangor? Some sort of requirement. We can give you numerous ways to split a file.
Posted: 16 Jun 2009 00:45
by ramesh
RElliott63 wrote:Ramesh,
You have to have some sort of criteria on breaking the file down. Number of records? Key field information? They way the sun sets over Bangor? Some sort of requirement. We can give you numerous ways to split a file.
We will be getting a vendor file daily and number of records will varyon daily basis. I wold like to split the file on record count.
Plese let me kow if you need anymore info
Posted: 16 Jun 2009 10:47
by RElliott63
Here's a Start for you:
Change "xxLimit" to how many records you want per file. %1 is the name of the file being sent from vendor.
Code: Select all
@Echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
Set /a "xxFileNo=1"
Set /a "xxLimit=10"
Set /a "xxRecCount=0"
Set "xxOutFile=OutFile.%xxFileNo%"
Set "xxInFile=%1"
for /f "delims=" %%L in (%xxInFile%) Do (
Echo %%L >> !xxOutFile!
Set /a xxRecCount+=1
If /I !xxRecCount! GEQ %xxLimit% (
Set /a xxFileNo+=1
Set "xxOutFile=OutFile.!xxFileNo!"
Set /a xxRecCount=0
)
)
Posted: 18 Jun 2009 22:15
by ghostmachine4
if you can get
GNU tools, you can use the split command.
eg assuming split by number of lines
Code: Select all
c:\workspace\> split -l 100 myfile