comparison rapsodyn/SplitFileUpTo10x.pl @ 9:0e7c6fe60646 draft

Uploaded
author mcharles
date Mon, 20 Oct 2014 05:58:31 -0400
parents
children
comparison
equal deleted inserted replaced
8:d857538d9fea 9:0e7c6fe60646
1 #!/usr/bin/perl
2 #V1.0.0
3 use strict;
4 use warnings;
5
6 my $in = $ARGV[0];
7 my $NB_LINE_GROUP = $ARGV[1];
8 my $NB_FILE = $ARGV[2];
9 my $out1 = $ARGV[3];
10 my $out2 = $ARGV[4];
11 my $out3 = $ARGV[5];
12 my $out4 = $ARGV[6];
13 my $out5 = $ARGV[7];
14 my $out6 = $ARGV[8];
15 my $out7 = $ARGV[9];
16 my $out8 = $ARGV[10];
17 my $out9 = $ARGV[11];
18 my $out10 = $ARGV[12];
19
20 if (($NB_FILE<2)||($NB_FILE>10)){
21 print STDERR "File must be split in 2-10\n";
22 exit(0);
23 }
24 my @in;
25 my $current_aggregate;
26 open(IN, $in) or die ("Can't open $in\n");
27 while (my $line =<IN>){
28 $current_aggregate = $line;
29 my $nb_line=1;
30 if ($NB_LINE_GROUP>1){
31 while (my $add_line = <IN>){
32 $current_aggregate .= $add_line;
33 $nb_line++;
34 if ($nb_line == $NB_LINE_GROUP){
35 last;
36 }
37 }
38 }
39 push (@in,$current_aggregate);
40 }
41 close (IN);
42
43 open (OUT1,">$out1") or die ("Can't open $out1");
44 open (OUT2,">$out2") or die ("Can't open $out2");
45 open (OUT3,">$out3") or die ("Can't open $out3");
46 open (OUT4,">$out4") or die ("Can't open $out4");
47 open (OUT5,">$out5") or die ("Can't open $out5");
48 open (OUT6,">$out6") or die ("Can't open $out6");
49 open (OUT7,">$out7") or die ("Can't open $out7");
50 open (OUT8,">$out8") or die ("Can't open $out8");
51 open (OUT9,">$out9") or die ("Can't open $out9");
52 open (OUT10,">$out10") or die ("Can't open $out10");
53
54
55 for (my $i=0;$i<=$#in;$i++){
56 if ($i <= $#in * 1 / $NB_FILE){
57 print OUT1 $in[$i];
58 }
59 elsif ($i <= $#in * 2 / $NB_FILE){
60 print OUT2 $in[$i];
61 }
62 elsif (($NB_FILE>=3)&&($i <= $#in * 3 / $NB_FILE)){
63 print OUT3 $in[$i];
64 }
65 elsif (($NB_FILE>=4)&&($i <= $#in * 4 / $NB_FILE)){
66 print OUT4 $in[$i];
67 }
68 elsif (($NB_FILE>=5)&&($i <= $#in * 5 / $NB_FILE)){
69 print OUT5 $in[$i];
70 }
71 elsif (($NB_FILE>=6)&&($i <= $#in * 6 / $NB_FILE)){
72 print OUT6 $in[$i];
73 }
74 elsif (($NB_FILE>=7)&&($i <= $#in * 7 / $NB_FILE)){
75 print OUT7 $in[$i];
76 }
77 elsif (($NB_FILE>=8)&&($i <= $#in * 8 / $NB_FILE)){
78 print OUT8 $in[$i];
79 }
80 elsif (($NB_FILE>=9)&&($i <= $#in * 9 / $NB_FILE)){
81 print OUT9 $in[$i];
82 }
83 elsif (($NB_FILE>=10)&&($i <= $#in * 10 / $NB_FILE)){
84 print OUT10 $in[$i];
85 }
86 else {
87
88 }
89
90
91 }
92
93
94 close (OUT1);
95 close (OUT2);
96 close (OUT3);
97 close (OUT4);
98 close (OUT5);
99 close (OUT6);
100 close (OUT7);
101 close (OUT8);
102 close (OUT9);
103 close (OUT10);
104
105
106
107
108
109
110