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 two files koti_rama Shell Programming and Scripting 4 06-10-2008 07:15 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 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 03-15-2007
mohan705 mohan705 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
join files

Hi ,
I want to join 2 files based on 2 column join condition.

a11

john 2230 5000

a12

XXX 2230 A B 200 345

Expected O/P


John 2230 5000 A B 200

I have tried this

awk 'NR==FNR{a[$2]=$1;next}a[$2]&&sub($1,a[$2])' a11 a12 > a13

john 2230 A B 200 345

Thannksinadvance
Mohan
  #2 (permalink)  
Old 03-15-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958

Code:
awk 'NR==FNR{a[$2]=$0;next}a[$2]&&sub($1,a[$2])&&sub($(NF - 4), "")' a11 a12

  #3 (permalink)  
Old 03-15-2007
mohan705 mohan705 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
Thanks ,its working fine


Thanks and Regards,
Mohan
  #4 (permalink)  
Old 03-15-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926
If the files are sorted:


Code:
join -1 2 -2 2 -o 1.1 1.2 1.3 2.3 2.4 2.5  a11 a12

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 11:04 AM.


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