Home Man
Search
Today's Posts
Register

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

Tags
join, shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 11-05-2009
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
# 2  
Old 11-05-2009
Something like this with awk:

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

# 3  
Old 11-05-2009
great!

thanks
D.
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 04:15 PM
how to join two files using "Join" command with one common field in this problem? mindfreak UNIX for Dummies Questions & Answers 2 04-13-2012 05:55 AM
awk command for simple join command but based on 2 columns ruby_sgp Shell Programming and Scripting 2 03-28-2010 07:00 AM
need help with join command ayu Shell Programming and Scripting 0 03-24-2010 08:25 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
Using Join Command Supial Shell Programming and Scripting 4 08-09-2005 01:12 AM
Join command unisam UNIX for Dummies Questions & Answers 4 07-28-2004 06:59 AM


All times are GMT -4. The time now is 02:10 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password