I wrote this script about a year ago, in August 1994, to solve a simple problem: moving large files when all you have are floppy disks and unreliable modem connections.
The situation comes up more than you would think. You have a file that is larger than a floppy disk. Maybe it is a software distribution, maybe a database dump. You need to get it from one machine to another, but the only reliable transport you have is a box of 1.44 MB floppies. Or you are transferring over a modem connection that drops after a certain file size and you need to break the transfer into smaller pieces.
Unix’s split normally divides text on line boundaries; GNU’s version also offers byte-count splitting. I wanted something that would split any file, binary or text, into pieces that fit on a floppy disk. And I wanted it to work everywhere I had Perl installed, which at this point means DOS, Unix, and Mac.
So I wrote split.pl. It reads a file byte by byte and writes out numbered pieces, each no larger than 1,400,000 bytes (a safe size for a 1.44 MB floppy with some room for the filesystem overhead).
Here is the script; the original file and usage notes are also available to download:
#!/usr/local/bin/perl
# Program name: split.pl
# Author: Rajiv Pant (Betul) [email protected] https://rajiv.org
# Version 1.0. August, 1994
# Note: Documentation is at end.
$BigFile = shift ;
$DiskSize = 1_400_000 ;
open (BIGFILE, $BigFile) ;
while (read (BIGFILE, $c, 1))
{
$SmallFileNumber = int (1 + $byte/$DiskSize) ;
if ($SmallFileNumber != $PreviousSmallFileNumber)
{
print "Creating new file: $BigFile.$SmallFileNumber\n" ;
open (SMALLFILE, ">$BigFile.$SmallFileNumber") ;
}
print SMALLFILE $c ;
$byte++ ;
$PreviousSmallFileNumber = $SmallFileNumber ;
}
close (SMALLFILE) ;
close (BIGFILE) ;
Run perl split.pl bigfile.tar.gz and it creates bigfile.tar.gz.1, bigfile.tar.gz.2, and so on. Each piece fits on a floppy. On DOS, first give the input a short name without an extension, such as BPG, so the pieces become BPG.1, BPG.2, and so on.
To combine the pieces, list every part in numeric order. For two parts on Unix: cat bigfile.tar.gz.1 bigfile.tar.gz.2 > bigfile.tar.gz. On DOS: copy /b BPG.1+BPG.2 BPG, then rename the result to its original name. Include each additional part explicitly; a * wildcard puts part 10 before part 2. The receiving machine needs no copy of the splitting script.
The script is intentionally simple. Reading one byte at a time favors clarity over speed. On systems such as DOS that distinguish text and binary files, add binmode(BIGFILE); after opening the input and binmode(SMALLFILE); after each output is opened, so line endings and control characters survive unchanged. Check that file opens, reads and writes succeed before relying on the resulting pieces.
I have used this on SunOS, Linux, DOS with a Perl port, and System 7. That is the nice thing about writing utilities in Perl: you write it once and carry it with you.