Split a file
Mar. 22nd, 2005 05:06 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Perl script that splits a file into 100 million-byte pieces. It system()s out to the dd utility, so it could be rewritten in pure Perl.
Usage example:
will produce lf0, lf1, lf2, lf3... until there are no more pieces.
Usage example:
split.pl largefile lf
will produce lf0, lf1, lf2, lf3... until there are no more pieces.
#!perl -w use strict; @ARGV >= 2 or die "Usage: $0 file prefix\n"; my $fname = shift; my $prefix = shift; my $fsize; defined($fsize = -s $fname) or die "Error stating file $fname: $!\n"; my $splitcount = int($fsize / 1e8); for my $i (0 .. $splitcount) { print "Split $i of $splitcount...\n"; system "dd if=$fname of=$prefix$i bs=100MD count=1 skip=$i"; } __END__