![]() |
|
|
|
|
|||||||
| 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 |
| 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 | Display Modes |
|
|||
|
drl,
I noticed you used sh in your script and I used bash when I did my interactive session. So I changed my shell to sh but still join did not work. Here is the session history: [chenz@beta binned]$ echo $0 bash [chenz@beta binned]$ sh sh-3.1$ echo $0 sh sh-3.1$ 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 sh-3.1$ cat data2 rs1003456 3 rs1005152 3 sh-3.1$ sort data1>t1 sh-3.1$ sort data2>t2 sh-3.1$ join t1 t2 sh-3.1$ |
| Forum Sponsor | ||
|
|
|
|||
|
As drl pointed out file1 and file 2 are not sorted. Sort both of 'em before trying the join operation to get the expected result.
Code:
sort -k1,1 file1 > file1srt sort -k1,1 file2 > file2srt join -j 1 file1srt file2srt |
|
|||
|
Thanks to Shamrock -- it's working now using the following syntax:
sort -k1,1 file1 > file1srt sort -k1,1 file2 > file2srt join -j 1 file1srt file2srt Out of curiosity: why the following not working? sort -k1 file1 > file1srt sort -k1 file2 > file2srt join -j 1 file1srt file2srt In any case, sincerely thanks to both drl and shamrock. |
|
|||
|
"sort -k1" sorts file on the entire line. The start field is 1 but as no end field is given it defaults to the end of the line. "sort -k1,1" specifies the start and end field to be 1 and so its output is different from the "sort -k1" case.
|