![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| join two files | koti_rama | Shell Programming and Scripting | 5 | 08-05-2008 01:20 AM |
| awk, join or sed | jkl_jkl | Shell Programming and Scripting | 1 | 04-15-2008 02:55 AM |
| join (pls help on join command) | summer_cherry | Shell Programming and Scripting | 1 | 12-31-2007 02:19 AM |
| Join help with -e option | Ken555 | UNIX for Dummies Questions & Answers | 2 | 08-21-2006 07:50 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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
|
||||
|
||||
|
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
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 |
|
#4
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |