-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMergeSampleSheet.pl
More file actions
44 lines (40 loc) · 1.1 KB
/
MergeSampleSheet.pl
File metadata and controls
44 lines (40 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use strict;
use warnings;
use Getopt::Long;
my $dir = "";
my $result = "";
my $skipLines = 8; #the first $skipLines lines will be considered as output header
GetOptions(
"d=s" => \$dir,
"o=s" => \$result,
);
opendir( DIR, "$dir" ) or die $!;
open RESULT, ">$result" or die $!;
my $countFile = 0;
while ( my $file = readdir(DIR) ) {
if ( $file =~ /.csv$/ ) {
$countFile++;
if ( $countFile == 1 ) { #the first file, use its first $skipLines lines as output header
print
"$countFile: Loading $file. Its first $skipLines lines will be used as result header.\n";
open READ, "<$dir/$file" or die $!;
while (<READ>) {
print RESULT $_;
}
close(READ);
}
else { #Not the first file, discard its first $skipLines lines
print
"$countFile: Loading $file. Its first $skipLines lines will be discarded.\n";
open READ, "<$dir/$file" or die $!;
my $lineCount = 0;
while (<READ>) {
$lineCount++;
if ( $lineCount <= $skipLines ) { next; }
print RESULT $_;
}
close(READ);
}
}
}
print "$result was successfully generated.\n";