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
Batch script to split a file into 4 files
Moderator: DosItHelp
-
- Expert
- Posts: 80
- Joined: 04 Feb 2009 10:03
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
-
- Expert
- Posts: 80
- Joined: 04 Feb 2009 10:03
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.
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
)
)
-
- Posts: 319
- Joined: 12 May 2006 01:13
if you can get GNU tools, you can use the split command.
eg assuming split by number of lines
eg assuming split by number of lines
Code: Select all
c:\workspace\> split -l 100 myfile