-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetRowsByCol.pl
More file actions
executable file
·41 lines (30 loc) · 893 Bytes
/
getRowsByCol.pl
File metadata and controls
executable file
·41 lines (30 loc) · 893 Bytes
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
#!/usr/bin/perl -w
if(scalar(@ARGV) != 5) {
print "Select rows with values specified in the <selectFile> with the <selectColumn>\n";
print "\nUsage: ~ <input_file> <column2select> <selectFile> <selectColumn> <outputFile>\n\n";
exit(1);
}
use Flat;
use Util;
my $cmdLine = Util::getCmdLine();
# read data from the file
my($in) = shift @ARGV;
my($inFlat) = Flat->new1($in);
my $fld2sel = $inFlat->getFieldIndex(shift @ARGV);
my $sFlat = Flat->new1(shift @ARGV);
my $sFld = $sFlat->getFieldIndex(shift @ARGV);
my $out = shift @ARGV;
open OUT, "+>$out.tmp" or die $!;
my(%rowVal2keep) = ();
while($row = $sFlat->readNextRow()) {
$rowVal2keep{$row->[$sFld]} = 1;
}
$sFlat->destroy();
while($row = $inFlat->readNextRow()) {
if(exists $rowVal2keep{$row->[$fld2sel]}) {
print OUT join("\t", @{$row}), "\n";
}
# else skip
}
close OUT;
Util::run("mv $out.tmp $out", 1);