suppose u have file
File A
A -> G
C->D
A -> R
P->A
File B
A=1
C=2
D=3
E=4
F=5
G=6
H=7
I=8
K=9
L=10
M=11
N=12
P=13
Q=14
R=15
S=16
T=17
V=18
W=19
Y=20
From File A and File B
output shud be such that
first one (A)shud have -1 and second one (G) shud have 1
so that
A -> G 1:-1 2:0 3:0 4:0 5:0 6:1 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
C->D 1:0 2:0 3:-1 4:1 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
so on......
How can we do that using perl or awk??
you are already exposed to perl/awk previously so your "newbie" license is already expired. what have you got so far?
Tried using perl
!/usr/bin/perl
open IN,"FILE A";
while($line=<IN>)
{
@free=split(/->/, $line);
$free1=$free[0];
$free2=$free[1];
chomp($free1);
chomp($free2);
#print $free1." ".$free2."\n";
}
open IN,"FILEB";
$line=<IN>;
$j=0;
while($line=<IN>)
{
@number=split('=', $line);
print $number[0]." ".$number[25]."\n";
for($i=0;$i<25;$i++)
{
$darray[$j][$i]=$number[$i];
#print $darray[$j][$i]." ";
}
$j++;
}
print "\n";
close (IN);
What can be the next unable to do that ???
perl:
my %hash;
while(<DATA>){
chomp;
my @tmp=split("=",$_);
$hash{$tmp[0]}=$tmp[1];
}
open $fh,"<","a.spl";
while(<$fh>){
chomp;
/([A-Z])\s*->\s*([A-Z])/;
print $_;
for(my $i=1;$i<=20;$i++){
if($i == $hash{$1}){
print " ",$i,":",-1;
}
elsif($i == $hash{$2}){
print " ",$i,":",1;
}
else{
print " ",$i,":",0;
}
}
print "\n";
}
__DATA__
A=1
C=2
D=3
E=4
F=5
G=6
H=7
I=8
K=9
L=10
M=11
N=12
P=13
Q=14
R=15
S=16
T=17
V=18
W=19
Y=20
summer_cherry:
perl:
my %hash;
while(<DATA>){
chomp;
my @tmp=split("=",$_);
$hash{$tmp[0]}=$tmp[1];
}
open $fh,"<","a.spl";
while(<$fh>){
chomp;
/([A-Z])\s*->\s*([A-Z])/;
print $_;
for(my $i=1;$i<=20;$i++){
if($i == $hash{$1}){
print " ",$i,":",-1;
}
elsif($i == $hash{$2}){
print " ",$i,":",1;
}
else{
print " ",$i,":",0;
}
}
print "\n";
}
__DATA__
A=1
C=2
D=3
E=4
F=5
G=6
H=7
I=8
K=9
L=10
M=11
N=12
P=13
Q=14
R=15
S=16
T=17
V=18
W=19
Y=20
Hello Summer cherry ,
After running this perl command
The result dispalyed is
A->G 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
C->D 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
A->R 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
P->A 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
But the output should be
in case of A->G first one (A)shud have -1 and second one (G) shud have 1 and .then in case of P->A P have -1 nad A have 1.....and so on....
A->G 1:-1 2:0 3:0 4:0 5:0 6:1 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
C->D 1:0 2:0 3:-1 4:1 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
A->R 1:-1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:1 16:0 17:0 18:0 19:0 20:0
P->A 1:1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:-1 14:0 15:0 16:0 17:0 18:0 19:0 20:0
thanks..
cdfd123:
...
After running this perl command
The result dispalyed is
A->G 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
C->D 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
A->R 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
P->A 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
...
Nope, that's wrong. The output is as expected:
$
$ cat a.spl
A->G
C->D
A->R
P->A
$
$ cat test_scr.pl
#!/usr/bin/perl -w
my %hash;
while(<DATA>){
chomp;
my @tmp=split("=",$_);
$hash{$tmp[0]}=$tmp[1];
}
open $fh,"<","a.spl";
while(<$fh>){
chomp;
/([A-Z])\s*->\s*([A-Z])/;
print $_;
for(my $i=1;$i<=20;$i++){
if($i == $hash{$1}){
print " ",$i,":",-1;
}
elsif($i == $hash{$2}){
print " ",$i,":",1;
}
else{
print " ",$i,":",0;
}
}
print "\n";
}
__DATA__
A=1
C=2
D=3
E=4
F=5
G=6
H=7
I=8
K=9
L=10
M=11
N=12
P=13
Q=14
R=15
S=16
T=17
V=18
W=19
Y=20
$
$ perl test_scr.pl
A->G 1:-1 2:0 3:0 4:0 5:0 6:1 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
C->D 1:0 2:-1 3:1 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0
A->R 1:-1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:1 16:0 17:0 18:0 19:0 20:0
P->A 1:1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:-1 14:0 15:0 16:0 17:0 18:0 19:0 20:0
$
$
tyler_durden