Join Question


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Join Question
# 1  
Old 12-13-2016
Join Question

Have two simple sorted text files:
Code:
file1
dog bark
cat meow
bird fly
goat baa

file2
dog loyal
cat herd
bird scratch
bird1 peck
goat milk

Using a simple join command is not picking up with word bird.
Code:
join file1 file2

Getting an error indicating that file2 is not sorted although it is. And bird is not being picked up.

This is the output after the error:
Code:
join: File 2 is not in sorted order
cat meow herd
dog bark loyal
goat baa milk

Any help would be appreciated.
# 2  
Old 12-13-2016
Your sample file2 as displayed is not sorted on the first column.

Code:
$ join file1 file2
bird fly scratch
cat meow herd
dog bark loyal
goat baa milk

Owner@Owner-PC ~
$ cat file1
bird fly
cat meow
dog bark
goat baa

Owner@Owner-PC ~
$ cat file2
bird scratch
bird1 peck
cat herd
dog loyal
goat milk

Works when both are sorted
# 3  
Old 12-13-2016
It's not working. The sort is correct, just not in my example.
# 4  
Old 12-13-2016
The first sample file isn't sorted either. If the sample does not represent your real situation, then please post a representative sample.
# 5  
Old 12-13-2016
Apologies, here is the actual sample:

Code:
>cat file1_sort
bird fly
cat meow
dog bark
goat baa

>cat file2_sort
bird1 peck
bird scratch
cat herd
dog loyal
goat milk

>join file1_sort file2_sort
join: File 2 is not in sorted order
cat meow herd
dog bark loyal
goat baa milk

# 6  
Old 12-13-2016
Code:
$ sort -b file2_sort
bird scratch
bird1 peck
cat herd
dog loyal
goat milk

# 7  
Old 12-13-2016
Scrutinizer, I'm doing the sort -b but it's returning the 'bird1' first. I think this is the problem. Is there a way to tell sort to put the numeric ones 2nd?

Code:
>sort -b file2_sort
bird1 peck
bird scratch
cat herd
dog loyal
goat milk

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join, merge, fill NULL the void columns of multiples files like sql "LEFT JOIN" by using awk

Hello, This post is already here but want to do this with another way Merge multiples files with multiples duplicates keys by filling "NULL" the void columns for anothers joinning files file1.csv: 1|abc 1|def 2|ghi 2|jkl 3|mno 3|pqr file2.csv: 1|123|jojo 1|NULL|bibi... (2 Replies)
Discussion started by: yjacknewton
2 Replies

2. Programming

Oracle 11g optimizer best join order question

Hi team Optimizer max permutations and search limit are set to 3.5 million and 10 respectively.The parameter instruct optimizer to evaluate up to 3.5 million permutations for max 10 table joins I have query with 9 tables joined. How many combinations will optimizer perform to find best... (1 Reply)
Discussion started by: Perlbaby
1 Replies

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

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

5. Shell Programming and Scripting

Join help

im trying to join 3 files together sort -n ${ASS1_DATA_DIR}Prac1 | sed '/^#/d' > ${ASS1_OUTPUT_DIR}Prac1temp sort -n ${ASS1_DATA_DIR}Prac2 | sed '/^#/d' > ${ASS1_OUTPUT_DIR}Prac2temp join -a1 -a2 -1 1 -2 1 -o "0 1.2 2.2" -e " " ${ASS1_OUTPUT_DIR}Prac1temp ${ASS1_OUTPUT_DIR}Prac2temp >... (6 Replies)
Discussion started by: bigubosu
6 Replies

6. Shell Programming and Scripting

Quick join question

I have to join(no other command is allowed) 3 files together. And im aware that i have to sort these files(file1 file2 file3) first before I can join them. However i have to output these sorted files to some temporary file. i can't just do sort -n file1 > file1 or i get an empty file output. Is... (3 Replies)
Discussion started by: bigubosu
3 Replies

7. UNIX for Dummies Questions & Answers

Join

Hi.. Just a question: Let's say we have three files: test1.txt --------- 11111111 6 12121212 7 12345678 4 11112222 8 test2.txt --------- 11111111 5 12345678 6 11112222 6 test3.txt --------- 12345678 6 12121212 8 (3 Replies)
Discussion started by: nelsonandwee
3 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

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
Login or Register to Ask a Question