How to merge data of file 1 to file 2 according to id
file 1
user id gene
123 wert
124 weetr
125 qwert
file 2
user id gene
123 wwerrt
126 qweq
111 wwqw
output file should be
output
file
user id gene
111 wwqw
123 wert
124 weetr
125 qwert
126 qweq
file 1
user id gene
123 wert
124 weetr
125 qwert
file 2
user id gene
123 wwerrt
126 qweq
111 wwqw
output file should be
output
file
user id gene
111 wwqw
123 wert
124 weetr
125 qwert
126 qweq
Code:
#!/usr/bin/perl use strict; # my $source_file1 = 'geno.txt'; # my $source_file2 = 'pheno.txt'; # my $dest_file = 'Output.txt'; my %hash = (); my $line; open(FINAL,">output.txt"); open(FILE1,'genotype_features.txt'); while($line = <FILE1>) { my ($GenotypeID,$GenotypeName,$GenotypeUniqueName,$AlleleID,$AlleleName,$AlleleAbbreviation,$AlleleType,$AlleleDisplayType,$GeneorConstructSymbol,$CorrespondingZFINGeneID)= split(/\s+/,$line); print $line; $hash{$GenotypeID} ={$GenotypeName,$GenotypeUniqueName,$AlleleID,$AlleleName,$AlleleAbbreviation,$AlleleType,$AlleleDisplayType,$GeneorConstructSymbol,$CorrespondingZFINGeneID}; #print $hash{$GenotypeID}; } close(FILE1); open ( FILE2, 'geno.ods'); open (my $FILE3, '>', $dest_file); while( $line = <FILE2>) { my ($GenotypeID,$GenotypeName,$StartStageOboID,$EndStageOboID,$Process1OboID,$Process2OboID,$PhenotypeKeywordID,$PhenotypeModifier,$PublicationZFINID,$EnvironmentZFINID)= split(/\t/, $line); # print $line; for(grep/^GenotypeID/,keys%hash) { print "$GenotypeID\t$hash{$GenotypeID}\t$GenotypeName\t$StartStageOboID\t$EndStageOboID\t$Process1OboID\t$Process2OboID\t$PhenotypeKeywordID\t$PhenotypeModifier\t$PublicationZFINID\t$EnvironmentZFINID\n"; } } # close($FILE3); close(FILE2); problem is comming in hash{genotypeid} they are not taking elements
Comment