combining two list according to one id..


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers combining two list according to one id..
# 1  
Old 05-13-2009
combining two list according to one id..

Hi,
I have two list I wanna combine and print them together in the output depending if they have the same rsid:
file1:
ENST00000262042 rs47 583 N D
ENST00000408005 rs48 583 N D
ENST00000311322 rs268 318 N S
file 2:
rs34 CHB T 1 C 0 T/T C/T C/C 1 0 0
rs47 JPT T 1 C 0 T/T C/T C/C 1 0 0
rs48 YRI T 1 C 0,017 T/T C/T C/C 1 0 0

output file shold be:
ENST00000262042 rs47 583 N D CHB T 1 C 0 T/T C/T C/C 1 0 0
ENST00000408005 rs48 583 N D JPT T 1 C 0 T/T C/T C/C 1 0 0

can i do it by means of command line*?

thanks for replies
# 2  
Old 05-13-2009
If rsid is the key the given desired output is not correct.

Regards
# 3  
Old 05-13-2009
i have to go through both list and for each line if the rsid is the same eg rs47 i need to print output as shown above
# 4  
Old 05-13-2009
why is CHB part of rs47? that's what franklin is asking you.
# 5  
Old 05-13-2009
ok my mistake, output should be like:
ENST00000262042 rs47 583 N D JPT T 1 C 0 T/T C/T C/C 1 0 0
ENST00000408005 rs48 583 N D YRI T 1 C 0 T/T C/T C/C 1 0 0
# 6  
Old 05-13-2009
if you have Python
Code:
d={}
for line in open("file1"):
    line=line.strip()
    L = line.split()
    d[L[1]] = line
for line in open("file2"):
    line=line.strip().split()
    if d.has_key(line[0]):
        print d[line[0]],' '.join(line[1:])

output
Code:
# ./test.py
ENST00000262042 rs47 583 N D JPT T 1 C 0 T/T C/T C/C 1 0 0
ENST00000408005 rs48 583 N D YRI T 1 C 0,017 T/T C/T C/C 1 0 0

# 7  
Old 05-13-2009
With awk:

Code:
awk '
NR==FNR{a[$1]=$0;sub($1,"",a[$1]);next}
$2 in a{print $0 a[$2]}
' file2 file1

Use nawk or /usr/xpg4/bin/awk on Solaris
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Combining Operators

Hey everyone, I'm really getting into learning C, but as I look at more advanced example code, I see things like if (!*variable1) blah blah blah... and variable2 ^= *(variable1++); my question is, when you have a combination of two operators, like !*. The ! means 'not' and the *... (2 Replies)
Discussion started by: Lost in Cyberia
2 Replies

2. Shell Programming and Scripting

How to get list of files only using ls without combining it with other command?

HI, I have requirement to fetch the list of files except the ok file by connecting to other server and then copy all the files that are fetched using the below command. ssh ${aSrcHOST} ls ${aSrcDIR}/grep -vi OK$ > filelist.txt The above code is also picking up any directory names and... (7 Replies)
Discussion started by: Nikhath
7 Replies

3. Shell Programming and Scripting

combining two images into one

Hi, I have two sets of image files. Both sets have names A to Z but set 1 ends with .cdt.png and set 2 ends with .matrix.png. I want set 1 to match with set 2 if the names match (i.e. A.cdt.png will match with A.matrix.png) and with the convert image tool (program for images), it will merge the... (1 Reply)
Discussion started by: kylle345
1 Replies

4. Shell Programming and Scripting

Combining 2 files

i am having 2 files like this file 1 1, 2, 3, 4, file2 5, 6, 7, 8, what i want do is like this i want to put all the contents for file 2 after file 1,means adding column in file1 (5 Replies)
Discussion started by: sagar_1986
5 Replies

5. Shell Programming and Scripting

combining two lists

Hi, So I I received two lists for my merchandise and both are similar but differences do occur. I want to combine two lists that have similar names but I dont want the similar name to come up twice because I will end up purchasing two of those items. Heres an example below (file is massive). ... (1 Reply)
Discussion started by: kylle345
1 Replies

6. Shell Programming and Scripting

combining 2 files into one according to the list

hi, i have a list of file: KB0002 KB215027 KB0003 KB215027 KB0004 KB215027 KB0005 KB204320 KB0006 KB207074 KB0007 KB215204 KB0008 KB223809 KB0009 KB236640 KB0010 KB244506 KB0011 KB205382 KB0012 KB212813 KB0013 KB236314 KB0014 KB230897 KB0015 KB232532 KB0016 KB231543... (2 Replies)
Discussion started by: karla
2 Replies

7. Red Hat

combining two/three line in to one

Hi Radoulov, I have tried the code for testing as I too required this on numbers of occasion to combining two line having length of 132 characters .I am using RedHat 9 Linux. I am using like if ( nr % 2 == o ) or if ( nr % 3 == 0 ) and fetching the data from the... (0 Replies)
Discussion started by: vakharia Mahesh
0 Replies

8. Shell Programming and Scripting

Combining 2 scripts

Hello I am new to shell scripting. Below are 2 scripts which I need to combine in to single script.Can some experts guide me how to proceed? #!/bin/bash grep "2443" /f/log/s/heduler.log | grep 2443> /tmp/memorydump exec 6<"/tmp/memorydump" read -u 6 data if then echo "IN THEN" <... (4 Replies)
Discussion started by: achararun
4 Replies

9. Shell Programming and Scripting

Combining Two Files

I have two files which contain data from two different transactions in the same format: <Name> - <Count> My goal is to end up with data in this format after combining the two: <Name> - <Count1> - <Count2> Is this possible to do with awk, or is there something better? Thanks... (3 Replies)
Discussion started by: bat711
3 Replies

10. UNIX for Dummies Questions & Answers

Combining Two Dirs

I have two Directories, foo and foobar. I want to combine the contents of foo into foobar. There is probably a simple command for this, but I have yet to find it. Thanks in advance, Robert (2 Replies)
Discussion started by: Phobos
2 Replies
Login or Register to Ask a Question