![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | 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 !! |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk, join or sed | jkl_jkl | Shell Programming and Scripting | 1 | 04-15-2008 02:55 AM |
| Join | jazz8146 | UNIX for Dummies Questions & Answers | 5 | 01-29-2008 07:42 AM |
| join (pls help on join command) | summer_cherry | Shell Programming and Scripting | 1 | 12-31-2007 01:19 AM |
| Use non alphanumerics in join | s0460205 | UNIX for Dummies Questions & Answers | 1 | 12-16-2005 03:03 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
join not working
I was trying to merge the following two example files using their first field:
join -1 1 -2 1 file1 file 2 but nothing is produced. The expected result should be: rs1005152 7 q21.3 3 It appears that the length of the first field in file1 is causing the problem. Any suggesting on how to use join to produce the desired result? I know there are other ways to get the result but I have to use the join because the real files are huge. Thanks in advance. file1: rs10051507 5 q21.3 rs10051514 5 p15.32 rs10051527 5 q21.2 rs1005152 7 q21.3 rs10051540 5 q21.3 rs10051548 5 q21.1 rs1005155 X q27.3 rs10051594 5 q34 file2: rs1003456 3 rs1005152 3 |
| Forum Sponsor | ||
|
|
|
||||
|
Hi.
Here is a script that produces results for files not sorted, then sorted: Code:
#!/usr/bin/env sh # @(#) s1 Demonstrate join. # ____ # / # | Infrastructure BEGIN echo set -o nounset 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. set +o nounset LC_ALL=C ; LANG=C ; export LC_ALL LANG echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG" echo "(Versions displayed with local utility \"version\")" version >/dev/null 2>&1 && version =o $(_eat $0 $1) sort join set -o nounset echo FILE1=data1 echo " Input file $FILE1:" cat $FILE1 echo FILE2=data2 echo " Input file $FILE2:" cat $FILE2 echo echo " Results expected:" cat expected-results # | Infrastructure END # \ # --- echo echo " Results from processing without a sort:" join $FILE1 $FILE2 echo echo " Results from processing after sorting files:" sort $FILE1 >t1 sort $FILE2 >t2 join t1 t2 exit 0 Code:
% ./s1 Environment: LC_ALL = C, LANG = C (Versions displayed with local utility "version") Linux 2.6.11-x1 GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu) sort (coreutils) 5.2.1 join (coreutils) 5.2.1 Input file data1: rs10051507 5 q21.3 rs10051514 5 p15.32 rs10051527 5 q21.2 rs1005152 7 q21.3 rs10051540 5 q21.3 rs10051548 5 q21.1 rs1005155 X q27.3 rs10051594 5 q34 Input file data2: rs1003456 3 rs1005152 3 Results expected: rs1005152 7 q21.3 3 Results from processing without a sort: Results from processing after sorting files: rs1005152 7 q21.3 3 |
|
|||
|
drl,
That's odd. I got the expected result when I ran your whole script. However when I ran each step of the script, join still did not work. Here is what I did: $ cat data1 rs10051507 5 q21.3 rs10051514 5 p15.32 rs10051527 5 q21.2 rs1005152 7 q21.3 rs10051540 5 q21.3 rs10051548 5 q21.1 rs1005155 X q27.3 rs10051594 5 q34 $ cat data2 rs1003456 3 rs1005152 3 $ sort data1 >t1 $ sort data2>t2 $ join t1 t2 Why is that? |
|||
| Google UNIX.COM |