From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 24-SEP-1993 14:08:30.42
To:	EVERHART
CC:	
Subj:	Re: need vms way to split large file to many smaller; like unix "split"

From: wayne@tachyon.com (Wayne Sewell)
X-Newsgroups: comp.os.vms
Subject: Re: need vms way to split large file to many smaller; like unix "split"
Message-ID: <1993Sep20.082240.239@tachyon.com>
Date: 20 Sep 93 08:22:40 CDT
Organization: Tachyon Software Consulting
Lines: 76
To: Info-VAX@KL.SRI.COM
X-Gateway-Source-Info: USENET

In article <CDICMF.BtL@usenet.ucs.indiana.edu>, swcramer@silver.ucs.indiana.edu (The Shadow) writes:
> 
> I have a large file on VMS, that I can not pull into any of the
> editors.  I am looking for a way to split the file up into smaller,
> more manageable files.  I know there is a command on unix "split -n"
> that will perform this task but I am looking for a way to do this same
> task within VMS without having to transfer the file over to unix.
> 
> Please respond through email, if possible, with any ideas on this...
> 
> Thanks,

I hacked the following Pascal program a couple of weeks ago.  To use it, define
the logical name "input_file" to be (you guessed it) the file you want broken
up.  It will create, in the default directory, outfile.001, outfile.002,
outfile.003, ... outfile.nnn.  Just rename the entire bunch to be the name you
want, i.e. "rename outfile.* name_you_want ".  It is currently hardcoded to
break every 1000 lines.

=========== cut here ======= start of split_out_by_count.pas ===============
[ INHERIT('sys$library:starlet','sys$library:pascal$lib_routines') ]
PROGRAM split_out_by_count(output);


type
   input_line = VARYING [5000] OF CHAR; 
 
VAR
    infile:TEXT;
    outfile:TEXT;
    current_line : input_line;
    line_count : integer;
    file_count, pad_len : integer;
    pad_str, file_num_str : varying [10] of char;

 
BEGIN
line_count := 0;
file_count := 1;
OPEN( infile, 'input_file', READONLY );   (* 'input_file' is a logical name *)
reset(infile);
OPEN( outfile, 'outfile.001' );           (* let's start with file number 1 *)
rewrite(outfile);
while not eof(infile) do begin
   line_count := line_count + 1;
   readln(infile,current_line);
   if (line_count >= 1000) then begin	  (* split every thousand lines *)
      line_count := 0;			  (* reset line count *)
      close(outfile);                     (* close current out file *)
      file_count := file_count + 1;       (* bump file count *)
      writev(file_num_str,file_count:1);  (* convert to ascii *)
      pad_len := 3 - length(file_num_str); (* get number of zeros to pad *)
      pad_str := '';
      if pad_len > 0 then                 (* if padding needed *)
         pad_str := substr('0000000000',1,pad_len); (* generate pad *)
      OPEN( outfile, 'outfile.' + pad_str + file_num_str); (* open next file *)
      rewrite(outfile);
      end;
   writeln(outfile,current_line);
   end;
close(infile);
close(outfile);
END.
=========== cut here ========= end of split_out_by_count.pas ===============

If you don't have Pascal, this can easily be rewritten in any high-level 
language, or in DCL.

Wayne
-- 
==============================================================================
Wayne Sewell                            |INET: wayne@tachyon.com
Tachyon Software Consulting             |UUCP: uupsi!uupsi6!tachyon!wayne
P. O. Box 550937, Dallas TX  75355-0937 |Voice: (214)-553-9760, Fax: -553-0077
=============================================================================
Elwood:"Is this the new Bluesmobile or what?"  Jake:"Fix the cigarette lighter."

