The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-03-2008
Registered User
 

Join Date: Jun 2007
Posts: 45
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.
Reply With Quote
Forum Sponsor
  #2  
Old 01-03-2008
Registered User
 

Join Date: Nov 2007
Posts: 85
I hope this is what u want

awk '{
if(NR==FNR) color[$1]=$2;
else if(color[$1]!="") print $0,color[$1];
}' T2 T1
Reply With Quote
  #3  
Old 01-03-2008
Registered User
 

Join Date: Jun 2007
Posts: 45
it's not working....
Reply With Quote
  #4  
Old 01-03-2008
Registered User
 

Join Date: Nov 2007
Posts: 85
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.
Reply With Quote
  #5  
Old 06-10-2008
Registered User
 

Join Date: Mar 2008
Posts: 17
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0