Merging fields --- Join is not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merging fields --- Join is not working
# 8  
Old 05-22-2009
@repinementer,

It would be difficult to understand wht your requiremnt is unless you post and mention ur requiemnt clearly

Pls post a simple and valid input and output your expecting
# 9  
Old 05-22-2009
Thanx alot

Thank you Vidhya and Cambridge for you valuble time and suggestions.
The codes are working great.
But vidhya ur code is good but not robust (I mean too slow!)
Anyways thanx once again.Smilie
Great Work
# 10  
Old 05-22-2009
Quote:
Originally Posted by vidyadhar85
its running fine
Code:
 
fnsonlu1-/home/> cat file1
1234
133
1345
134
23
4555
fnsonlu1-/home/> cat file2
1234 tab kshgjkghj
23 tab drjghfg
134 tab drkhgjgj
1345 tab djghf
4555 tab khdjhgjfg
133tabjghhdgf
fnsonlu1-/home/l> while read line ; do
awk '$1'==$line'{print '$line'"\t"$0}' file2
done < vv
1234    1234 tab kshgjkghj
1345    1345 tab djghf
134     134 tab drkhgjgj
23      23 tab drjghfg
4555    4555 tab khdjhgjfg

usually, there's no need to use while read loop again if you are using awk.
Code:
# awk 'FNR==NR{ a[$1]=$0; next}a[$1]!=""{print $1,a[$1]}' file2 file1
# awk 'FNR==NR{ a[$1]; next}($1 in a){  print $1,$0}' file1 file2

# 11  
Old 05-26-2009
Hi

Hi Vidhya

Thanks for great script
How could I run the same script if I have more columns in the second file??
Could you plz help me on this.

Hi Ghost dog

Your commands are working like heaven Thank you so muchSmilie

Last edited by repinementer; 05-28-2009 at 05:49 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to combine fields with sort/join

I have a file with two fields in it delimited by a comma. Some of the first fields are duplicates. I am trying to eliminate any duplicate records in the first field, and combine the second fields in the output file. For example, if the input is: Jane,group=A Bob,group=A Bob,group=D... (3 Replies)
Discussion started by: DJR
3 Replies

2. Shell Programming and Scripting

Merging fields in CSV

Hi experts, I have a csv file which has one field (ID) repeated multiple times with corresponding other field values. I need to convert this file in a format where for a ID all other values has to be present in single field. For Eg : Here in below file ID 1 is repeated 3 times with different... (7 Replies)
Discussion started by: bharathbangalor
7 Replies

3. Shell Programming and Scripting

Merging files with common IDs without JOIN

Hi, I am trying to merge information across 2 files. The first file is a "master" file, with all IDS. File 2 contains a subset of IDs of those in File 1. I would like to match up individuals in File 1 and File 2, and add information in File 2 to that of File 1 if they appear. However, if an... (3 Replies)
Discussion started by: hubleo
3 Replies

4. Shell Programming and Scripting

Join fields comparing 4 fields using awk

Hi All, I am looking for an awk script to do the following Join the fields together only if the first 4 fields are same. Can it be done with join function in awk?? a,b,c,d,8,,, a,b,c,d,,7,, a,b,c,d,,,9, a,b,p,e,8,,, a.b,p,e,,9,, a,b,p,z,,,,9 a,b,p,z,,8,, desired output: ... (1 Reply)
Discussion started by: aksijain
1 Replies

5. Shell Programming and Scripting

join fields

My input is as below: 1|2|3|a02 test|303 2|2|4|1002 a05 ind|303 4|3|5|ind|30 Output 1|2|3|a02test|303 2|2|4|a05ind|303 4|3|5|ind|30 I used command: I am getting above output. Is there any simple way using awk to acheive this. Thanks. Please use code tags! (6 Replies)
Discussion started by: Jairaj
6 Replies

6. UNIX for Dummies Questions & Answers

Need help with Join on multiple fields

Hi, I need help with the join command I have 2 files that I want to join on multiple fields. I want to return all records from file 1 I also want empty fields in my joined file if there isn't a match in file 2 I have already sorted them so I know they are in the same order. file1 ... (0 Replies)
Discussion started by: shunter0810
0 Replies

7. Shell Programming and Scripting

Merging two files by comparing three fields

Hi Experts, I need your timely help. I have a problem with merging two files. Here my situation : Here I have to compare first three fields from FILE1 with FILE2. If they are equal, I have to append the remaining values from FILE2 with FILE1 to create the output. FILE1: Class ... (3 Replies)
Discussion started by: Hunter85
3 Replies

8. Shell Programming and Scripting

Merging fields --- Help me plz

INPUT have a file with 2 columns. evry set in a column ends with a symbol //. the first one with something like chr, chr no, chromosome name, cell no. cell no. etc and the second column has values belong to the first columnlike chr Xy, 22, 345,22222 etc. Some clumns have repeated but not... (4 Replies)
Discussion started by: bogu0001
4 Replies

9. Shell Programming and Scripting

merging fields from 2 different files.

File 1 3337304 2 4 DH.ER@TORONTO.CA 20080504 04622 3337305 2 4 A@C.COM 20080504 04622 3337306 2 4 JO@NET.NET 20080504 04622 3337307 2 4 L@GMAIL.COM 20080504 05344 2479201 2 2 ORY@YAHOO.COM 20080504 05344 File 2 ... (5 Replies)
Discussion started by: rudoraj
5 Replies

10. Shell Programming and Scripting

join on multiple fields

Is it possible to do a join on multiple fields of two files? I am trying to do something like join -t, -1 2,3 -2 2,3 -o 2.1,2.2,2.3,1.3 filea fileb I want the join to be on columns 2 and 3 of filea and columns 2 and 3 of fileb. What is hapenning is that the second file that I want to do the join... (1 Reply)
Discussion started by: reggiej
1 Replies
Login or Register to Ask a Question