sugar has asked for the wisdom of the Perl Monks concerning the following question:
The result file has contents of second file for similar TAT id's and content of first file for different(unique between two files) TAT id's. the program which i have written is not giving me the right answer. Please have a look at it:file1.txt: 234 13 4 49 + TAT_01 id_nu1 explan1 236 123 3 67 + TAT_02 id_nu2 explan2 534 12 8 13 + TAT_03 id_nu3 explan3 764 124 9 33 + TAT_04 id_nu4 explan4 224 153 2 37 + TAT_05 id_nu5 explan5 file2.txt: 334 138 34 39 - TAT_02 PAS_1 id_nu2 new2 545 154 83 11 + TAT_03 PAS_2 id_nu3 new3 765 131 21 12 - TAT_05 PAS_3 id_nu5 new5 desired_results: 234 13 4 49 + TAT_01 id_nu1 explan1 334 138 34 39 - TAT_02 PAS_1 id_nu2 new2 545 154 83 11 + TAT_03 PAS_2 id_nu3 new3 764 124 9 33 + TAT_04 id_nu4 explan4 765 131 21 12 - TAT_05 PAS_3 id_nu5 new5
please suggest me a better way to solve this problem. Thank you very much !!#!/usr/bin/perl open(FH1,"file1.txt"); open(FH2,"file2.txt"); @array=<FH2>; $jo=join("",@array); @spl=split("\n",$jo); while($line1=<FH1>){ @hold=(); @coll=split("\t",$line1); #$len=$coll[1]-$coll[2]; #$len=~s/-//g; $hit=$coll[5]; @hold=grep(/$hit/,@array); $held=shift(@hold); if(defined $held){ ($c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8,$c9)=split("\t",$held +); print "$c1\t$c2\t$c3\t$c4\t$c5\t$c6\t$c7\t$c8\t$c9\n"; } else{ print "$coll[0]\t$coll[1]\t$coll[2]\t$coll[3]\t$coll[4 +]\t$coll[5]\t$coll[6]\t$coll[7]\t$coll[8]\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: combining two files based on missing values
by lostjimmy (Chaplain) on Jun 04, 2009 at 18:27 UTC | |
|
Re: combining two files based on missing values
by bichonfrise74 (Vicar) on Jun 04, 2009 at 18:31 UTC |