how to match a numers from file1 to file 2??Ps help me..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to match a numers from file1 to file 2??Ps help me..
# 1  
Old 04-15-2010
how to match a numers from file1 to file 2??Ps help me..

Hi firends,
I need to write a program in perl for following task,
I have a data like following numbers in file1.txt
Code:
1061338
1159781
1161717
1920355
1924487
2996733
3121872
3124510

I have to search the matching numbers in file2,my file2 is have a multiple columns like this
Code:
rs3934834	  1	   1045729	   A	G	0.1791	0.2054	0.8441	
rs3737728	  1	   1061338	   A	G	0.2845	0.2809	1.018	
rs6687776	  1	   1070488	   A	G	0.1768	0.1956	0.8833
rs9651273	  1	   1071463	   A	G	0.2743	0.2689	1.028	
rs4970405	  1	   1088878	   G	A	0.0922	0.0757	1.24	
rs1272625	  1	   1089873   G	A	0.1369	0.1231	1.13	
rs2298217	  1	   1104902   A	G	0.1448	0.1542	0.9286	
rs4970362	  1	   1134661	   A	G	0.3793	0.3954	0.9346

the underlined column have to matched with file1..But i dont know how to write a program for this task..I need out put like file2 for matching numbers only...Pls any one help me & give me a program in perl..
my output should be like
Code:
rs6596796	6	120522	A	G	0.1058	0.09469	
rs1535053	6	126089	G	A	0.2155	0.2151	
rs12192106	6	137664	A	G	0.06956	0.07949	
rs6913464	6	139090	A	G	0.1702	0.1663	
rs9405480	6	144199	A	G	0.1869	0.1771	
rs9392299	6	148909	G	A	0.07122	0.06203	
rs1418708	6	150610	A	G	0.1386	0.1374
rs1418707	6	150800	G	A	0.192	       0.1631


Last edited by zaxxon; 04-15-2010 at 03:42 AM.. Reason: use code tags please, ty
# 2  
Old 04-15-2010
I didn't understand the following statement in your question.
The third column of file2 have a matching numbers of file 2.

my understanding is , Need to match the 3rd column of file2 with file1 content. You need a output from file2 matched lines with file1.

Give me your desired output.
# 3  
Old 04-15-2010
Quote:
Originally Posted by Nila
I didn't understand the following statement in your question.
The third column of file2 have a matching numbers of file 2.

my understanding is , Need to match the 3rd column of file2 with file1 content. You need a output from file2 matched lines with file1.

Give me your desired output.
Hi Nila thanks for reply,

simply say i have match the file1 & file 2.the file2 have data like as i said before..the third column of file2 have a matching numbers with file1.which means
Code:
rs6596796	6	120522	A	G	0.1058	0.09469	1.132	
rs1535053	6	126089	G	A	0.2155	0.2151	1.003	
rs12192106	6	137664	A	G	0.06956	0.07949	0.86	
rs6913464	6	139090	A	G	0.1702	0.1663	1.028	
rs9405480	6	144199	A	G	0.1869	0.1771	1.068	
rs9392299	6	148909	G	A	0.07122	0.06203	1.16	
rs1418708	6	150610	A	G	0.1386	0.1374	1.01	
rs1418707	6	150800	G	A	0.192	0.1631	1.219

the under lined numbers r have to match with file1...and my output should be like this..
Code:
rs6596796	6	120522	A	G	0.1058	0.09469	1.132	
rs1535053	6	126089	G	A	0.2155	0.2151	1.003	
rs12192106	6	137664	A	G	0.06956	0.07949	0.8657	
rs6913464	6	139090	A	G	0.1702	0.1663	1.028	
rs9405480	6	144199	A	G	0.1869	0.1771	1.068	
rs9392299	6	148909	G	A	0.07122	0.06203	1.16	
rs1418708	6	150610	A	G	0.1386	0.1374	1.01	
rs1418707	6	150800	G	A	0.192	        0.1631	1.219	3.

pls help me nila..this is very urgent..write a program for this task

Last edited by zaxxon; 04-15-2010 at 03:42 AM.. Reason: use code tags please, ty
# 4  
Old 04-15-2010
From the data it looks like the data issorted.
The file1 is sorted.
And file2 is sorted on column 3.
Is this correct?
Then I would consider Unix "paste" is the best command.
# 5  
Old 04-15-2010
[root]# perl -lane "BEGIN { open(FH,'file1');@con=<FH>;}print if grep(/@F[2]/,@con)" file2
rs3737728 1 1061338 A G 0.2845 0.2809 1.018

Thanks,
Penchal

---------- Post updated at 12:39 AM ---------- Previous update was at 12:35 AM ----------

Quote:
Originally Posted by sureshraj
Hi firends,
I need to write a program in perl for following task,
I have a data like following numbers in file1.txt

1061338
1159781
1161717
1920355
1924487
2996733
3121872
3124510

I have to search the matching numbers in file2,my file2 is have a multiple columns like this
rs3934834 1 1045729 A G 0.1791 0.2054 0.8441
rs3737728 1 1061338 A G 0.2845 0.2809 1.018
rs6687776 1 1070488 A G 0.1768 0.1956 0.8833
rs9651273 1 1071463 A G 0.2743 0.2689 1.028
rs4970405 1 1088878 G A 0.0922 0.0757 1.24
rs1272625 1 1089873 G A 0.1369 0.1231 1.13
rs2298217 1 1104902 A G 0.1448 0.1542 0.9286
rs4970362 1 1134661 A G 0.3793 0.3954 0.9346

the underlined column have to matched with file1..But i dont know how to write a program for this task..I need out put like file2 for matching numbers only...Pls any one help me & give me a program in perl..
my output should be like
rs6596796 6 120522 A G 0.1058 0.09469
rs1535053 6 126089 G A 0.2155 0.2151
rs12192106 6 137664 A G 0.06956 0.07949
rs6913464 6 139090 A G 0.1702 0.1663
rs9405480 6 144199 A G 0.1869 0.1771
rs9392299 6 148909 G A 0.07122 0.06203
rs1418708 6 150610 A G 0.1386 0.1374
rs1418707 6 150800 G A 0.192 0.1631
Hi ,

if third coulmn of file2 matches with file1 in above case ,

output must be

rs3737728 1 1061338 A G 0.2845 0.2809 1.018

Am i right

Thanks,
Penchal
# 6  
Old 04-15-2010
If it is not sorted then try this:
Code:
while read xx ; do
 egrep " $xx " file2
done < file1

Not the best. Draw backs:
1. If you have 10,000 records in file1 then you will be calling egrep so many times.
2. This code is not looking for the value exclusively in column 3, but in the whole record. That is, if column 1 has the same value then you are .......
# 7  
Old 04-15-2010
Try this,

Code:
use strict;
use warnings;
use Data::Dumper;


open FH1,"file" or die "Can't open the file $!";
open FH2,"file1" or die "Can't open the file $!";
open OUTPUT,"+>output_file" or die "Can't open the file $!";

while (<FH1>)
{
        my $line=$_;

        while (<FH2>)
        {
                my ($a,$b,$c)=split(' ');
                if($c == $line)
                {
                        print OUTPUT $_ ;
                }

        }
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to match file1 and extract specific tag values

File2 is tab-delimeted and I am trying to use $2 in file1 (space delimeted) as a search term in file2. If it is found then the AF= in and the FDP= values from file2 are extracted and printed next to the file1 line. I commented the awk before I added the lines in bold the current output resulted. I... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Shell Programming and Scripting

awk to search field2 in file2 using range of fields file1 and using match to another field in file1

I am trying to use awk to find all the $2 values in file2 which is ~30MB and tab-delimited, that are between $2 and $3 in file1 which is ~2GB and tab-delimited. I have just found out that I need to use $1 and $2 and $3 from file1 and $1 and $2of file2 must match $1 of file1 and be in the range... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

Print sequences from file2 based on match to, AND in same order as, file1

I have a list of IDs in file1 and a list of sequences in file2. I can print sequences from file2, but I'm asking for help in printing the sequences in the same order as the IDs appear in file1. file1: EN_comp12952_c0_seq3:367-1668 ES_comp17168_c1_seq6:1-864 EN_comp13395_c3_seq14:231-1088... (5 Replies)
Discussion started by: pathunkathunk
5 Replies

4. Shell Programming and Scripting

Match single line in file1 to groups of lines in file2

I have two files. File 1 is a two-column index file, e.g. comp11084_c0_seq6:130-468(-) comp12746_c0_seq3:140-478(+) comp11084_c0_seq3:201-539(-) comp12746_c0_seq2:191-529(+) File 2 is a sequence file with headers named with the same terms that populate file 1. ... (1 Reply)
Discussion started by: pathunkathunk
1 Replies

5. Shell Programming and Scripting

Need to select some column from file1 if condition match.

I have two files file1.txt and file2.txt. want to print some column(number,status,date1,date2,description(descrption column end before category column start with'Oracle Services') and assigned_to column from file1.txt ...If the assigned_to name in file2.txt matches with assinged_to name in... (2 Replies)
Discussion started by: vijay_rajni
2 Replies

6. Shell Programming and Scripting

Match part of string in file2 based on column in file1

I have a file containing texts and indexes. I need the text between (and including ) INDEX and number "1" alone in line. I have managed this: awk '/INDEX/,/1$/{if (!/1$/)print}' file1.txt It works for all indexes. And then I have second file with years and indexes per year, one per line... (3 Replies)
Discussion started by: phoebus
3 Replies

7. Shell Programming and Scripting

Based on column in file1, find match in file2 and print matching lines

file1: file2: I need to find matches for any lines in file1 that appear in file2. Desired output is '>' plus the file1 term, followed by the line after the match in file2 (so the title is a little misleading): This is honestly beyond what I can do without spending the whole night on it, so I'm... (2 Replies)
Discussion started by: pathunkathunk
2 Replies

8. Shell Programming and Scripting

Match one column of file1 with that of file2

Hi, I have file1 like this aaa ggg ddd vvv eeeand file2 aaa 2 aaa 443 xxx 76 aaa 34 ggg 33 wee 99 ggg 33 ddd 1 ddd 10 ddd 98 sds 23 (4 Replies)
Discussion started by: polsum
4 Replies

9. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

10. Shell Programming and Scripting

match value from file1 in file2

Hi, i've two files (file1, file2) i want to take value (in column1) and search in file2 if the they match print the value from file2. this is what i have so far. awk 'FILENAME=="file1"{ arr=$1 } FILENAME=="file2" {print $0} ' file1 file2 (2 Replies)
Discussion started by: myguess21
2 Replies
Login or Register to Ask a Question