Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

join command

Shell Programming and Scripting


Tags
join

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-05-2009   -   Original Discussion by Dedalus
Dedalus's Unix or Linux Image
Dedalus Dedalus is offline
Registered User
 
Join Date: May 2009
Last Activity: 25 April 2013, 11:48 AM EDT
Posts: 102
Thanks: 9
Thanked 1 Time in 1 Post
join command

Hi

my problem is:
I've 2 files like:

file1:
Quote:
1 3.791406e-03 65388.3
6 8.568031e-01 1.47768e+07
17 1.323488e-01 2.28255e+06
47 5.928275e-03 102242
50 1.037607e-03 17895
89 9.085876e-05 1566.99
file2
Quote:
1 3.839507e-03 66217.9
6 8.563433e-01 1.47689e+07
10 0.000000e+00 0
17 0.000000e+00 0
..so many zeros
47 5.863369e-03 101122
50 1.020259e-03 17595.9
..so many zeros
89 0.0000000e+00 0
..so many zeros
I'd like to get file_out:
Quote:
 
1 3.791406e-03 65388.3 3.839507e-03 66217.9
6 8.568031e-01 1.47768e+07 8.563433e-01 1.47689e+07
17 1.323488e-01 2.28255e+06 0.000000e+00 0
47 5.928275e-03 102242 5.863369e-03 101122
50 1.037607e-03 17895 1.020259e-03 17595.9
89 9.085876e-05 1566.99 0.0000000e+00 0
I mean if the field is different from zero in the first file i want take that field also in the second(no matter if in the second is zero).

I tried with the join command but it doesn't work always and i don't understand why.
Can anyone help please?

thanks in advance

D
Sponsored Links
    #2  
Old Unix and Linux 11-05-2009   -   Original Discussion by Dedalus
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 8 May 2018, 10:20 AM EDT
Location: The Netherlands
Posts: 7,747
Thanks: 139
Thanked 558 Times in 520 Posts
Something like this with awk:



Code:
awk 'NR==FNR{a[$1]=$2 FS $3; next}a[$1]{print $0 FS a[$1]}' file2 file1

Sponsored Links
    #3  
Old Unix and Linux 11-05-2009   -   Original Discussion by Dedalus
Dedalus's Unix or Linux Image
Dedalus Dedalus is offline
Registered User
 
Join Date: May 2009
Last Activity: 25 April 2013, 11:48 AM EDT
Posts: 102
Thanks: 9
Thanked 1 Time in 1 Post
great!

thanks
D.
Sponsored Links
Closed

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
using join command ehshi1992 Shell Programming and Scripting 4 10-26-2009 02:39 PM
join command bgmmk Shell Programming and Scripting 1 03-03-2009 05:16 PM
Join command Mish_99 Shell Programming and Scripting 1 10-24-2008 11:27 AM
join (pls help on join command) summer_cherry Shell Programming and Scripting 1 12-31-2007 04:19 AM



All times are GMT -4. The time now is 12:46 PM.