using perl for matching one file with another file and print into new line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using perl for matching one file with another file and print into new line
# 1  
Old 03-24-2009
using perl for matching one file with another file and print into new line

One file is
fileA
0.0246*0.0068*0.0013*0.0023*0.0182*0.0028*0.0019*0.4750*0.0028*0.0812*0.0123*0.0018*0.0039*0.0020*0. 0028*0.0047*0.0139*0.3330*0.0017*0.0072*0.4789
0.0234*0.0062*0.0013*0.0023*0.0214*0.0027*0.0021*0.2783*0.0029*0.2001*0.0141*0.0017*0.0037*0.0021*0. 0030*0.0045*0.0124*0.4077*0.0019*0.0081*0.5228
0.0156*0.0045*0.0044*0.0075*0.0132*0.0037*0.0109*0.1374*0.0091*0.0489*0.5817*0.0082*0.0038*0.0765*0. 0141*0.0081*0.0110*0.0288*0.0034*0.0092*0.5426

Second file is file B
I85V
L95I
I103M


So using perl, i want to get the output
I=0.4750 V=0.0017
L=0.2001 I=0.0214
I=0.1374 M=0.5817

So so for symbols having 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


writing perl using Switch command..
can u further how can i do it...

Code:
#!/usr/bin/perl -w

use Switch;

print "PLEASE ENTER THE FILENAME OF THE FILE:=";
chomp($prot_psap=<STDIN>);

open(PROTFILE,$prot_psap) or die "unable to open the file";
@prot=<PROTFILE>;
close PROTFILE;
foreach $line (@prot) {

#$line ="s/*//g";
if ($line =~ s/^>//g) {
next;
}
else {
$sequence = $line;
}
$sequence  =~ s/\*/ /g;

@prota=split('',$sequence);
print @prota;
}

print "PLEASE ENTER THE FILENAME OF THE FILE:=";
chomp($mutation_file=<STDIN>);

open(MUTFILE,$mutation_file) or die "unable to open the file";
@mut=<MUTFILE>;
close MUTFILE;

foreach $line (@mut) {
if ($line =~ s/^>//g) {
next;
}
else {
$mutation = $line;
#$i=0;
}
$mutation  =~ s/[^A-Z]/ /g;


@muta=  split('',$mutation);

print @muta,"\n";
}

# 2  
Old 03-25-2009
Code:
my %hash=(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);
open $fh,"<","a.spl";
my %hash1;
while(<$fh>){
	my @tmp=split(/\*/,$_);
	for(my $i=0;$i<=$#tmp;$i++){
		$hash1{$.}->{$i+1}=$tmp[$i];
	}
}
close $fh;
open $fh,"<","a.txt";
while(<$fh>){
	my @tmp=split("",$_);
	map {print $_,"=",$hash1{$.}->{$hash{$_}},"," if $_=~/[A-Z]/} @tmp;
	print "\n";
}

This User Gave Thanks to summer_cherry For This Post:
# 3  
Old 03-25-2009
Maybe summer cherry understood the relationship between the two files and your output, but I don't.
# 4  
Old 03-25-2009
reply

Quote:
Originally Posted by KevinADC
Maybe summer cherry understood the relationship between the two files and your output, but I don't.
Quote:
Originally Posted by KevinADC
Maybe summer cherry understood the relationship between the two files and your output, but I don't.
Thanks summercherry

Simple thing is i have one file
which is having numbers separated by *
22*23*78*72*88

and another second file contains
A222D
# 5  
Old 03-25-2009
Quote:
Originally Posted by cdfd123
Thanks summercherry

Simple thing is i have one file
which is having numbers separated by *
22*23*78*72*88

and another second file contains
A222D
Whatever....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to update file with partial matching line in another file and append text

In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

awk to lookup stored variable in file and print matching line

The bash bash below extracts the oldest folder from a directory and stores it in filename That result will match a line in bold in input. In the matching line there is an_xxx digit in italics that (once the leading zero is removed) will match a line in link. That is the lint to print in output.... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

4. Shell Programming and Scripting

Replace line in file with line in another file based on matching string

HI Can any one guide me how to achieve this task. I have 2 files env.txt #Configuration.Properties values identity_server_url = http://identity.test-hit.com:9783/identity/service/user/register randon_password_length = 6 attachment_file_path = /pass/temp/attachments/... (1 Reply)
Discussion started by: nikilbr86
1 Replies

5. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

6. Shell Programming and Scripting

Replace line in file with line in another file based on matching string

Hi I am not the best scripter in the world and have run into a issue which you might be able to guide me on... I have two files. File1 : A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB File2: C345,... (5 Replies)
Discussion started by: luckycharm
5 Replies

7. Shell Programming and Scripting

Match a line in File 1 with Column in File 2 and print whole line in file 2 when matched

Hi Experts, I am very new to scripting and have a prb since few days and it is urgent to solve so much appreciated if u help me. i have 2 files file1.txt 9647810043118 9647810043126 9647810043155 9647810043161 9647810043166 9647810043185 9647810043200 9647810043203 9647810043250... (22 Replies)
Discussion started by: mustafa.abdulsa
22 Replies

8. Shell Programming and Scripting

Print matching lines in a file

Hello everyone, I have a little script below: die "Usage infile outfile reGex" if @ARGV != 3; ($regex) = @ARGV; open(F,$ARGV) or die "Can't open"; open(FOUT,"+>$ARGV") or die "Can't open"; while (<F>) { print FOUT if /$regex/.../$regex/; } No matter what I give $regex on the... (2 Replies)
Discussion started by: new bie
2 Replies

9. Shell Programming and Scripting

How to print file without few exactly matching lines?

Hi I have a very long file with 4 columns of numbers for example 1875 1876 12725 12723 13785 13786 4232 4230 13184 13185 ... (2 Replies)
Discussion started by: ananyob
2 Replies

10. Shell Programming and Scripting

Identify matching data in a file and output to original line, in perl

Hi, I haven't done this for awhile, and further, I've never done it in perl so I appreciate any help you can give me. I have a file of lines, each with 5 data points that look like this: AB,N,ALLIANCEBERNSTEIN HLDNG L.P,AB,N ALD,N,ALLIED CAPITAL CORPORATION,ALD,N AFC,N,ALLIED CAPITAL... (4 Replies)
Discussion started by: Pcushing
4 Replies
Login or Register to Ask a Question