473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to merge data of file 1 to file 2 according to id?

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

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3.     use strict;
  4.  
  5.  
  6.    # my $source_file1 = 'geno.txt';
  7.     # my $source_file2 = 'pheno.txt';
  8.  #   my $dest_file     =  'Output.txt';
  9.  
  10.     my %hash = ();
  11.     my $line;
  12.     open(FINAL,">output.txt");
  13.     open(FILE1,'genotype_features.txt');
  14.         while($line = <FILE1>) 
  15. {
  16.  
  17.      my ($GenotypeID,$GenotypeName,$GenotypeUniqueName,$AlleleID,$AlleleName,$AlleleAbbreviation,$AlleleType,$AlleleDisplayType,$GeneorConstructSymbol,$CorrespondingZFINGeneID)= split(/\s+/,$line);
  18. print $line;
  19.                $hash{$GenotypeID} ={$GenotypeName,$GenotypeUniqueName,$AlleleID,$AlleleName,$AlleleAbbreviation,$AlleleType,$AlleleDisplayType,$GeneorConstructSymbol,$CorrespondingZFINGeneID};
  20.             #print $hash{$GenotypeID};
  21.  
  22.   }
  23.     close(FILE1); 
  24.  
  25.     open ( FILE2, 'geno.ods');     
  26.       open (my $FILE3, '>', $dest_file);
  27.        while( $line = <FILE2>) 
  28. {
  29.      my ($GenotypeID,$GenotypeName,$StartStageOboID,$EndStageOboID,$Process1OboID,$Process2OboID,$PhenotypeKeywordID,$PhenotypeModifier,$PublicationZFINID,$EnvironmentZFINID)= split(/\t/, $line);
  30.  
  31.  
  32.   # print $line;
  33.                for(grep/^GenotypeID/,keys%hash)  {
  34.  
  35.  
  36.                    print "$GenotypeID\t$hash{$GenotypeID}\t$GenotypeName\t$StartStageOboID\t$EndStageOboID\t$Process1OboID\t$Process2OboID\t$PhenotypeKeywordID\t$PhenotypeModifier\t$PublicationZFINID\t$EnvironmentZFINID\n";
  37.  
  38.  
  39.                                   }
  40.        }
  41.  
  42.  
  43.     # close($FILE3);
  44.     close(FILE2);
  45. problem is comming in hash{genotypeid} they are not taking elements
Jan 28 '11 #1
4 1730
chorny
80 Expert
So values from first file take precedence?

Read second file into hash with id as key, than first file. Sort it numerically and output.
Jan 28 '11 #2
chorny
80 Expert
Use a third argument to split to make it split only to two fields.

Expand|Select|Wrap|Line Numbers
  1. my ($GenotypeID,$rest)= split(/\s+/,$line,2);
Jan 31 '11 #3
hey chorny thanks for reply but i am only getting the coloumns and not the data

ex:

file
userid gene
111
123
124
125
126

The information is not comming do help me please
Feb 1 '11 #4
dude i didn't get the answers

Please do help me
Feb 2 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Thomas Lotze | last post by:
Hi, another question: What's the most efficient way of copying data between two file-like objects? f1.write(f2.read()) doesn't seem to me as efficient as it might be, as a string containing...
0
by: JohnLH | last post by:
Hi, I am having an issue with the LOAD DATA LOCAL FILE command on the latest 3.0.9 JDBC Driver. The command works on Windows, but doesn't seem to work on OSX and Linux. The error that I get on...
14
by: Luiz Antonio Gomes Pican?o | last post by:
How i can store a variable length data in file ? I want to do it using pure C, without existing databases. I'm thinking to use pages to store data. Anyone has idea for the file format ? I...
5
by: Joe Van Dyk | last post by:
I have a file that looks like this: 25.000000 55.000000 23.000000 51.000000 5 8 8700 6000 <and then, at byte 128, starts binary stuff> What's the proper way to make sure that I'm reading in...
2
by: Bill | last post by:
I have an Access 2003 database application that I split into an application component MDB file (i.e., forms, etc) and a data component MDB file (i.e., tables, etc.). I used the 2003 developer...
4
by: tlcvetan158 | last post by:
Hi, I'm a newbie at C++. I am just trying to read a file with three columns of data into arrays and write it back out, to see how arrays work. This runs with no errors, but the output doesn't look...
2
abdoelmasry
by: abdoelmasry | last post by:
hi any one can help me plz ?? my code is about opening file as binary then get data from file to edit and rewrite data to file this is the code: #include <cstdlib> #include <iostream>...
3
by: psbasha | last post by:
Hi , When ever we read any data from file ,we read as a single line string ,and we convert the respective field data available in that string based on the data type ( say int,float ). ...
0
ADezii
by: ADezii | last post by:
Rather than using CurrentProject.Connection or entering your own Connection information, ADO supports storing Connection information in an external file called a Data Link File (which normally has a...
6
by: Dave067 | last post by:
Hi This is my first attempt at writing Python script - it's probably a bit ambitious, but there again, whatever doesn't kill you makes you stronger... ;-) I'm trying to write a script for a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.