join command and delimiters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting join command and delimiters
# 1  
Old 05-19-2009
join command and delimiters

I am using the join command to join information from two files that have a common field. Here are some examples:

field1:

99900 543
99903 333
99998 120
10000 222
100001 333
100005 220

field2:

99900 2009-05
99903 2009-05
99998 2009-05
100000 2009-05
100001 2009-05
100005 2009-05

I use the command like this:

join -t " " file1 file2 |sort -un > file3

The result is this:

99900 543 2009-05
99903 333 2009-05
99998 120 2009-05

It seems to stop when it gets to 100000.

So, I tried this:

join file1 file2 |sort -un > file3

I get the same result.

I assume that the default delimiter is white space, no matter how many, so the latter command should work. The former command denotes one space, which is not true, since it actually is two spaces.

So, I am confused as to why this works fine up to 99998, but will go no further.
# 2  
Old 05-19-2009
Code:
field1:

99900 543
99903 333
99998 120
10000 222   ten thousand
100001 333
100005 220

field2:

99900 2009-05
99903 2009-05
99998 2009-05
100000 2009-05  one hundred thousand, not ten thousand
100001 2009-05
100005 2009-05

10000 does not equal 100000
# 3  
Old 05-19-2009
Thanks for your reply. That was a typo on my part. It actually is 100000 and not 10000. It behaves the same as I reported, breaking at 99998.
# 4  
Old 05-19-2009
Then something else is wrong in that data. Instead of trying to type the data, cut and paste the data up here on the forums so we can see what it really is.
# 5  
Old 05-19-2009
Okay, here is a sample, cut and pasted:

file 1

99997 410
99998 410
100000 410
100001 410

file 2

99997 2009-05
99998 2009-04
99998 2009-04
99998 2009-04
99998 2009-04
99998 2009-04
99998 2009-04
99998 2009-05
99999 2009-04
99999 2009-04
99999 2009-04
99999 2009-04
99999 2009-04
99999 2009-04
99999 2009-04
99999 2009-04
99999 2009-04
100000 2009-04
100000 2009-04
100000 2009-04
100000 2009-04
100000 2009-04
100000 2009-04
100000 2009-04
100000 2009-04
100000 2009-04
100000 2009-04
100000 2009-04
100000 2009-04
100000 2009-04
100000 2009-05
100001 2009-04
100001 2009-04
100001 2009-04
100001 2009-04
100001 2009-04
100001 2009-04
100001 2009-05
100002 2009-04
100002 2009-04
100002 2009-04
100002 2009-04
100002 2009-04
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join Two Files, Each With Different Delimiters

Hello All, I am trying to join two files, each with differing delimiters. file1 has doe, john 10.00 60.00 4.00 5.00 doe, jane 10.00 60.00 4.00 5.00 ...while file2 has the following content: doe, johnz 10.00::60.00:4.00:5.00 doe, janet 10.00:60.00::4.00:5.00 Currently, I have join... (2 Replies)
Discussion started by: techieg
2 Replies

2. 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

3. UNIX for Dummies Questions & Answers

how to join two files using "Join" command with one common field in this problem?

file1: Toronto:12439755:1076359:July 1, 1867:6 Quebec City:7560592:1542056:July 1, 1867:5 Halifax:938134:55284:July 1, 1867:4 Fredericton:751400:72908:July 1, 1867:3 Winnipeg:1170300:647797:July 15, 1870:7 Victoria:4168123:944735:July 20, 1871:10 Charlottetown:137900:5660:July 1, 1873:2... (2 Replies)
Discussion started by: mindfreak
2 Replies

4. Shell Programming and Scripting

awk command for simple join command but based on 2 columns

input1 a_a a/a 10 100 a1 a_a 20 200 b1 b_b 30 300 input2 a_a a/a xxx yyy a1 a1 lll ppp b1 b_b kkk ooo output a_a a/a 10 100 xxx yyy (2 Replies)
Discussion started by: ruby_sgp
2 Replies

5. Shell Programming and Scripting

need help with join command

Hello, I am using join to merge two files together. The defaults usually works great join file1 file2 However, sometimes file1 or file2 has more keys, which I want to keep. file 1: -1 z 0 a 1 b 2 c file 2: 0 a2 1 b2 2 c2 3 c3 So I do join -a1 -a2 file1 file2 But then you don't... (0 Replies)
Discussion started by: ayu
0 Replies

6. Shell Programming and Scripting

join command

Hi my problem is: I've 2 files like: file1: file2 I'd like to get file_out: I mean if the field is different from zero in the first file i want take that field also in the second(no matter if in the second is zero). I tried with the join command but it doesn't work always and i don't... (2 Replies)
Discussion started by: Dedalus
2 Replies

7. Shell Programming and Scripting

join (pls help on join command)

Hi, I am a new learner of join command. Some result really make me confused. Please kindly help me. input: file1: LEO oracle engineer 210375 P.Jones Office Runner ID897 L.Clip Personl Chief ID982 S.Round UNIX admin ID6 file2: Dept2C ID897 6 years Dept5Z ID982 1 year Dept3S ID6 2... (1 Reply)
Discussion started by: summer_cherry
1 Replies

8. Shell Programming and Scripting

Using Join Command

Greetings, I am attempting to use the join command to produce a file from 2 sorted comma seperated files. Ex.: FILE 1: jane,dow joe,blow FILE 2: jane,dow,50,50,20 joe,blow,29,53,25 spike,lee,50,91,05 I want the resulting file to be reconds in FILE 2 where the person exists in FILE... (4 Replies)
Discussion started by: Supial
4 Replies

9. UNIX for Dummies Questions & Answers

Join command

Hi, I am trying to join 2 files..viz f1: 12~a1 13~a2 112~a3 1112~a4 f2: 12~fa2 13~fa2 112~fa3 1112~fa4 while I join..I just get 2 o/p.. 12~a1~fa2 13~a2~fa2 (4 Replies)
Discussion started by: unisam
4 Replies
Login or Register to Ask a Question