-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_add_Caseless.pl
72 lines (66 loc) · 1.31 KB
/
fetch_add_Caseless.pl
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/perl
use strict;
use warnings;
if (@ARGV<6)
{
print "perl $0 <file1> <key filed> <file2> <key filed of 1 > <filed of file2 added to file1[1,2,3|a]> <Number of \"-\" add for formating>\n";
print "Index from 0 \n";
print "a shoule be all value of the filed 2\n";
print "Add info from file2 to file1 \n\n";
exit;
}
open IN,"$ARGV[2]"or die "can not open file\n";
my %key_hash;
my $v_2=$ARGV[4];
my $num_N=$ARGV[5];
#my $case=$ARGV[5];
while(<IN>)
{
if(!/^#/)
{
chomp;
my @info=split(/\t/);
if($v_2 ne "a")
{
my @a_colum=split(/,/,$v_2);
my $add_info;
foreach my $item (@a_colum)
{
$add_info.=$info[$item]."\t";
}
if(!exists $key_hash{uc($info[$ARGV[3]])})
{
$key_hash{uc($info[$ARGV[3]])}=$add_info;
}
}
else
{$key_hash{uc($info[$ARGV[3]])}=$_;}
#print $info[$ARGV[3]],"\t",$info[$ARGV[4]],"\n";
}
}
close IN;
open IN ,"$ARGV[0]" or die "can not open file\n\n";
while(<IN>)
{
chomp;
my @info=split;
#print $info[$ARGV[1]],"\n";
# print $key_hash{$info[$ARGV[1]]},"\n";
if(exists($key_hash{uc($info[$ARGV[1]])}))
{
print $_,"\t",$key_hash{uc($info[$ARGV[1]])},"\n";
}
else
{
print $_;
if($num_N)
{
for (my $i=1;$i<=$num_N;$i++)
{
print "\t", "-";
}
}
print "\n";
}
}
close IN;