Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Join files by second column

UNIX for Dummies Questions & Answers


 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-19-2013
radius radius is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 4 December 2016, 9:14 PM EST
Posts: 134
Thanks: 50
Thanked 0 Times in 0 Posts
Join files by second column

I have file input

file1


Code:
1/1/2013    A    553.0763397    96    16582
1/1/2013    B    459.8333588    195    11992
1/2/2013    A    844.2973022    306    19555
1/2/2013    B    833.9300537    457    20165
1/3/2013    A    563.6917419    396    13879
1/3/2013    B    632.0749969    169    21205
1/4/2013    C    48.33055687    41    1596

file2


Code:
A    X1    X3    X5    X7    X9
B    X2    X3    X6    X7    X9
C    X1    X4    X5    X8    X9
D    X3    X2    X1    X4    X8

I need to join file1 and file2 ..i expect the output tobe:

file output


Code:
1/1/2013    A    553.0763397    96    16582    X1    X3    X5    X7    X9
1/1/2013    B    459.8333588    195    11992    X2    X3    X6    X7    X9
1/2/2013    A    844.2973022    306    19555    X1    X3    X5    X7    X9
1/2/2013    B    833.9300537    457    20165    X2    X3    X6    X7    X9
1/3/2013    A    563.6917419    396    13879    X1    X3    X5    X7    X9
1/3/2013    B    632.0749969    169    21205    X2    X3    X6    X7    X9
1/4/2013    C    48.33055687    41    1596    X1    X4    X5    X8    X9

thanks for the help

Last edited by radius; 07-19-2013 at 04:22 AM..
Sponsored Links
    #2  
Old Unix and Linux 07-19-2013
vidyadhar85's Unix or Linux Image
vidyadhar85 vidyadhar85 is offline Forum Advisor  
The Tutor
 
Join Date: Jun 2008
Last Activity: 23 March 2016, 5:15 AM EDT
Location: INDIA, Bangalore
Posts: 2,050
Thanks: 16
Thanked 105 Times in 102 Posts
try...


Code:
awk 'NR==FNR{v=$1;$1="";A[v]=$0;next}
{print $0" "A[$2]}' file2 file1

The Following User Says Thank You to vidyadhar85 For This Useful Post:
radius (07-19-2013)
Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to use the the join command to join multiple files by a common column evelibertine UNIX for Dummies Questions & Answers 5 07-05-2012 05:15 PM
join two files based on one column newpro Shell Programming and Scripting 3 04-26-2012 06:07 PM
Join 3 or more files using matching column cyz700 Shell Programming and Scripting 3 04-27-2011 09:04 AM
Join multiple files by column with awk macsx82 Shell Programming and Scripting 10 09-18-2010 05:56 PM
Join 2 files using first column vanesa1230 UNIX for Dummies Questions & Answers 2 06-27-2010 12:45 AM



All times are GMT -4. The time now is 05:53 AM.