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 and shell scripting languages 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 05:20 AM
Join columns from 2 files osramos Shell Programming and Scripting 2 11-14-2007 05:25 AM
how to join files jxh461 UNIX for Dummies Questions & Answers 5 08-23-2007 08:11 AM
join files mohan705 Shell Programming and Scripting 3 03-15-2007 06:51 AM
Join Files choppas Shell Programming and Scripting 2 10-18-2006 11:03 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-03-2008
koti_rama koti_rama is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 50
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.
  #2 (permalink)  
Old 01-03-2008
ranjithpr ranjithpr is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 157
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 (permalink)  
Old 01-03-2008
koti_rama koti_rama is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 50
it's not working....
  #4 (permalink)  
Old 01-03-2008
ranjithpr ranjithpr is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 157
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 (permalink)  
Old 06-10-2008
patelamit009 patelamit009 is offline
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0