![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| join two files | koti_rama | Shell Programming and Scripting | 5 | 08-05-2008 01:20 AM |
| Join columns from 2 files | osramos | Shell Programming and Scripting | 2 | 11-14-2007 02:25 AM |
| how to join files | jxh461 | UNIX for Dummies Questions & Answers | 5 | 08-23-2007 04:11 AM |
| join files | mohan705 | Shell Programming and Scripting | 3 | 03-15-2007 03:51 AM |
| Join Files | choppas | Shell Programming and Scripting | 2 | 10-18-2006 07:03 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Join two files
Hi
I have two files t1 and t2.please find the Desc about the files: T1: PART_ID1 DESCRIPTION SIZE 1 Seat Cover Large 2 Ash Tray Small 3 Floor Mat Medium T2: PART_ID2 COLOR 1 Blue 3 Black 4 Yellow I would you like output like : PART_ID DESCRIPTION COLOR 1 Seat Cover Blue 3 Floor Mat Black Please help me on this join. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
I hope this is what u want
awk '{
if(NR==FNR) color[$1]=$2; else if(color[$1]!="") print $0,color[$1]; }' T2 T1 |
|
#3
|
|||
|
|||
|
it's not working....
|
|
#4
|
|||
|
|||
|
I tried the script with ur sample input, and it was working. Its not working means is giving any syntax error or its giving wrong result. And the heading is not printed in the script u can add BEGIN in the awk script and print the heading.
|
|
#5
|
|||
|
|||
|
Try this....
As you have not specified the record delimiter, I assuming it as comma (,). awk -F, 'NR==FNR {a[$1]=$2} NR!=FNR {if(a[$1]=="") {next} print $1,$2,a[$1] }' T2 T1 You will get the expected output. Thanks Amit |
|||
| Google The UNIX and Linux Forums |