in reply to split of files
If I understand correctly, you have a file with a number of records, each one beginning with a line:
INPUT SEQUENCE=XXX
and ending with:
______________________________________________________________________ +___________________________________
And you want to split the whole file in smaller files containing N or these records
The easiest way I can imagine doing this is using Tie::File. Try this script:
#!/usr/bin/perl use strict; use warnings; use Tie::File; my ($file,$recs_X_file) = @ARGV; die "Usage: $0 <input_file> <recs x file>" if (@ARGV != 2); tie my @arr, 'Tie::File', $file, recsep => "__________________________ +_____________________________________________________________________ +__________",autochomp=>0; my $from=0; my $to=$recs_X_file-1; while ($from < $#arr){ my $ofile = "file.$from-$to"; open F,">",$ofile or die $!; print "printing records $from to $to in $ofile\n"; print F @arr[$from..$to]; $from=$to+1; $to = $from+$recs_X_file-1; }
This script interfaces the file as an array, but in the way that you want it to do: Each record in the array corresponds with one logical record in the file. Once done, it splits the array (i.e. the records in the file) N by N records and outputs them in sub-files
For example, if you call the script "split_records.pl" you can invoke it with:
perl split_records.pl inputfile 10
Outputs:
printing records 0 to 9 in file.0-9 printing records 10 to 19 in file.10-19 printing records 20 to 29 in file.20-29 ... and so on (depending on the number of records of the original file
Of course, the files containing the records are created too
Hope this helps!
citromatik
|
|---|