How to split a file into multiple files of equal size

Attached is a spec called SPLITFILE.SPX that will split a split a file into multiple files of equal size.

~Comment>PURGESAMEChange Numfiles to the number of different files you want to write outChange the defines for Input and Inputopt to match the name and type of input you are readingChange the defines Output and OutputOpt to match the name and type of output you want.  Be sure to reserve part of the name for the number of the file.Comment in the Define Random if you want the files to be randomly subsetted.  Default is that every Nth record is put in the Nth file. For instance, if you create 4 files, 1st file will have records, 1,5,9, and so on.  2nd file will have 2,6,10, etc, etc. >Define @NumFiles   4>Define @Input      Splitfile.Dat>Define @InputOpt   ASCII=20>Define @Output     Splitfiles.dat>Define @OutputOPt  ASCII''>Define @Random ''DON'T CHANGE ANYTHING BELOW THIS LINE****************************************************************************~In @Input, @InputOpt>IfDefine @Random~Out $SplitTmp~Sort RandomValue~In $SplitTmp>EndifNumBuf=2, Study=Orig>Repeat $A=1,...,@NumFiles~Out @Output~$A, @OutputOpt, #$A>EndRepeat~In $,NewBuf,Study=Temp~Def Proc=Splitit:M Temp![!1.2] += 1>Repeat $A=1,...,@NumFilesIf Temp![1.2] = $AWriteCase #$AGoto DoneEndif>EndRepeatDone:If Temp![1.2] = @NumFilesM Temp![1.2] = 0Endif}~Exc Proc=Splitit on Orig>IfDefine @Random~In;>Delete SplitTmp>Endif ~End

  • splitfile.spx
  • splitfile.dat