The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

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 04:20 AM
awk, join or sed jkl_jkl Shell Programming and Scripting 1 04-15-2008 05:55 AM
join (pls help on join command) summer_cherry Shell Programming and Scripting 1 12-31-2007 05:19 AM
Join help with -e option Ken555 UNIX for Dummies Questions & Answers 2 08-21-2006 10:50 PM

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

Join Date: Nov 2007
Posts: 20
Join

Hi,
Is there a way to get join to join 2 files even if in one file one of the records does not exist?
i.e. 1st file
aaa 50
bbb 60
2nd file
aaa 40

So i want to join the 2 files together and get the following output:
aaa 50 aaa 40
bbb 60 bbb 0

Is this possible???
Thanks
Jason
  #2 (permalink)  
Old 01-27-2008
vakharia Mahesh vakharia Mahesh is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 51
join

For successfule join commd execution
(1) sort both the file in same order the field on which you want to join
(2) the length must be same

use the commd: join file1 file2 > o/p file name
  #3 (permalink)  
Old 01-27-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 704
Hi.

On some versions of join, the lengths need not be the same. This may not result in the exact output you want, but non-matching lines can be included:
Code:
#!/usr/bin/env sh

# @(#) s1       Demonstrate feature.

#  ____
# /
# |   Infrastructure BEGIN

set -o nounset
echo

debug=":"
debug="echo"

## The shebang using "env" line is designed for portability. For
#  higher security, use:
#
#  #!/bin/sh -

## Use local command version for the commands in this demonstration.

echo "(Versions displayed with local utility \"version\")"
uname -rs
version >/dev/null 2>&1 && version bash join

echo

FILE1=${1-data1}
echo " Input file $FILE1:"
cat $FILE1

echo
FILE2=${1-data2}
echo " Input file $FILE2:"
cat $FILE2

# |   Infrastructure END
# \
#  ---

echo
echo " Results from processing:"
join -a 1 -e 0 $FILE1 $FILE2

exit 0
Producing:
Code:
$ ./s1

(Versions displayed with local utility "version")
SunOS 5.10
GNU bash 3.00.16
join (local) - no version provided.

 Input file data1:
aaa 50
bbb 60

 Input file data2:
aaa 40

 Results from processing:
aaa 50 40
bbb 60
See man pages for details ... cheers, drl
  #4 (permalink)  
Old 01-28-2008
vakharia Mahesh vakharia Mahesh is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 51
join

Thanks drl for throwing the lights on the subject , but as far as SCO-UNIX,
UNIX-VER5 are concerned I have experimented and found that if the length
is not equal of the field on which you wanted to join , it fails , same on
RedHat-9 too. Correct me if I am wrong , b'Coz on many occassion I have
seen if the file say if you want to join on strings and the same is not
sorted on -d order or digit not sorted on -n order and the likewise it gave me NIL output. But would like to have your suggestion too . Alwasy ready
to LEARN new things. Thanx in advance to discuss on the subject.
  #5 (permalink)  
Old 01-28-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 704
Hi, vakharia Mahesh.

I think we may be talking about different lengths. I was talking about the length of the files which might be different if it is the case that "one of the records does not exist" as the OP wrote.

I agree that the fields need to be the same length in characters, and the files need to be sorted on the fields to be joined. If the fields are not the same length, then one would need to do some pre-and-post processing to add extra fields, join, remove extra fields. One could also create an awk or perl script for such special cases.

Best wishes ... cheers, drl
  #6 (permalink)  
Old 01-29-2008
vakharia Mahesh vakharia Mahesh is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 51
join

Thanx drl for your response on the subject and removing the doubt
and as far as the length of file is concerned it does not matter for
successful operation of join commd.

Thanks once again D R L c u
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 03:49 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