join not working


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers join not working
# 8  
Old 05-08-2008
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$
# 9  
Old 05-08-2008
Hi.

Yes, I think the LC_ALL and LANG settings may have something to do with it. It looks like you are running RedHat 5.

Note that your default LANG is neither C nor null, both of which worked for me.

You can try entering this interactively:
Code:
LC_ALL=C ; LANG=C ; export LC_ALL LANG

and then enter the steps again.

I have no additional thoughts. Perhaps someone will stop by with some advice ... cheers, drl
# 10  
Old 05-08-2008
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

# 11  
Old 05-08-2008
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.
# 12  
Old 05-08-2008
Quote:
Originally Posted by gamma_user
Out of curiosity: why the following not working?

sort -k1 file1 > file1srt

sort -k1 file2 > file2srt

join -j 1 file1srt file2srt
"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.
# 13  
Old 05-09-2008
Thanks a lot, shamrock.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX Join not working as expected

Hello All, I'm working on a Shell script to join data from two files using Join command but not able to get the desired output as its throwing me an error: I have sorted the two files on the Column 1 numerically which is used as Join clause File 1: 1,ABC,GGG,20160401 2,XYZ,KKK,20160401... (2 Replies)
Discussion started by: venkat_reddy
2 Replies

2. UNIX for Dummies Questions & Answers

Join not working

Hi all, I'm trying to use the join command to merge two files, but it's not finding lots of the matches. I have three files in total: File A: 31_77 34_46 72_61 85_10 85_23 110_33 144_45 154_25 154_90 170_5 170_44 217_63 255_19 333_20 333_23 333_32 (2 Replies)
Discussion started by: HEP
2 Replies

3. Shell Programming and Scripting

Join not working properly

I want to join two files , with file 1 col 3 and file 2 col 1 as key. The join command is erratic for some reason. File 2 is a master file having all the names, and file 1 has some values. I want to add the names from fil2 in file 1. If I use the original master file, some output is missing. ... (16 Replies)
Discussion started by: ritakadm
16 Replies

4. Shell Programming and Scripting

Join not working for comparision

Hi All, I have 2 files where the first column of both the files have to be compared and if they match the first six columns of the first file to be extracted in the output file. Format of files : File1 : ${SHTEMP}NPBR5.XTR.tmp S00016678|129|7|MPF|20090106|E... (3 Replies)
Discussion started by: nua7
3 Replies

5. UNIX for Dummies Questions & Answers

A simple join, but nothing is working out for me

Guys, I want to join two files. You might have seen this many times. I just don't get the desired output. Searching the forum, No proper links :( Input: File1 test1 test2 test3 File2 is bad is not bad Output Needed: test1 is bad test2 is bad (4 Replies)
Discussion started by: PikK45
4 Replies

6. UNIX for Dummies Questions & Answers

How to use the the join command to join multiple files by a common column

Hi, I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column). I want to write a script to join the files by the first common column so that in the... (5 Replies)
Discussion started by: evelibertine
5 Replies

7. Shell Programming and Scripting

Bash join script not working

So i'm currently working on a project where I'm attempting to display information of users from the /etc/passwd file and also another information file holding addition information about users. Problem is I've been trying to join the two files together and have all of the information about each... (2 Replies)
Discussion started by: Nostyx
2 Replies

8. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies

9. Programming

sql,multiple join,outer join issue

example sql: select a.a1,b.b1,c.c1,d.d1,e.e1 from a left outer join b on a.x=b.x left outer join c on b.y=c.y left outer join d on d.z=a.z inner join a.t=e.t I know how single outer or inner join works in sql. But I don't really understand when there are multiple of them. can... (0 Replies)
Discussion started by: robbiezr
0 Replies

10. Shell Programming and Scripting

Merging fields --- Join is not working

Hi GUYS sorry for putting simple query. I have tried the methods posted previously in this site but I'm unable to join the similar values in different columns of different files. I used sort -u file1 and join but no use.?? I'm attaching my inputfiles.Plz chek them I have two files. 1st file... (10 Replies)
Discussion started by: repinementer
10 Replies
Login or Register to Ask a Question