Javeed Sar wrote: >
perl -e 'print <>' splitfile.1 splitfile.2 splitfile.3 splitfile.4 splitfile.5 > splitfile.new.txtHow to combine it back after split???
note the ordering is different, because the program below sends the next record to the next filehandle in a circle. The above one liner dumps the contents of the files sequentially. But if your datafile implementation is sound that shouldnt matter.
Todd W.
James Kipp wrote:I am working on a Windows NT box and I don't have the luxury of any file splitting utilities. We have a data file with fixed length records. I was wondering the most efficient way of splitting the file into 5 smallerfiles.Thought ( Hoping :-) ) some one out there may have done something likethis.Thanks !!#!/usr/bin/perl -w use strict; # call new() with named args found in init() to override defaults my( $fSpliter ) = Text::FileSplitter->new(); $fSpliter->split(); print( "done!\n" ); package Text::FileSplitter; use strict; use IO::File; sub new { my($class, %args) = @_; my($self) = bless( { %args }, $class ); $self->init(); return( $self ); } sub init { my($self) = shift(); my($filehandles) = []; $self->{ file } ||= './splitfile.txt'; $self->{ output_prefix } ||= ( ($self->{ file } =~ /(\w+)/) and $1 ); $self->{ file_count } ||= 5; $self->{ record_length } ||= 10; $self->{ fh } = IO::File->new( "< $self->{ file }" ) or die("open $self->{ file }: $!"); foreach ( 1 .. $self->{ file_count } ) { push( @{ $filehandles }, IO::File->new("> $self->{ output_prefix }.$_") ); } $self->{ ofh } = $filehandles; } sub split { my($self) = shift(); my($buffer); my($counter) = 0; while ( sysread $self->{ fh }, $buffer, $self->{ record_length } ) { $self->{ ofh }[ $counter % $self->{ file_count } ]->print( $buffer ); $counter++; } }
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]