Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"join" doesn't work as expected

Status
Not open for further replies.

ETStudi

Technical User
Apr 22, 2008
2
DE
Hello all,

I have a big problem using the command "join" with awk. I have two input files:


file1.txt
1 A
2 B
3 C
4 D
5 E
6 F
7 G
8 H
9 I
10 J
11 K
12 L
13 M



and file2.txt
2 222
5 555
6 666
6 666_2
8 888
9 999
10 101010
11 111111
13 131313



If I use the command

join file1.txt file2.txt > output.txt

within an awk script, I get the following - expected - result:

output.txt
2 B 222
5 E 555
6 F 666
6 F 666_2
8 H 888
9 I 999
10 J 101010
11 K 111111
13 M 131313


That's great!


-----8<----------------------------------------


But if I modify file2.txt and delete the entry "9", than awk ends the output after the line with the entry 8. I don't understand, why awk "forgets" the lines 10-13:


file2.txt
2 222
5 555
6 666
6 666_2
8 888
10 101010
11 111111
13 131313



The result is output.txt:
2 B 222
5 E 555
6 F 666
6 F 666_2
8 H 888



I don't know, what is the problem cause or if there is a workaround for this problem. I'm very thankful for all answers.


Reagrds

ET
 
join file1.txt file2.txt > output.txt
The above is NOT awk but shell !
Anyway, the files must be sorted for the join command and "10" is less than "9".

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
In other words, join expects the keys to be sorted alphabetically, not numerically.

Annihilannic.
 
Hello PHV and Annihilannic,

Thank you very much for your reply. I thought it was AWK, because the script which contains this line is named with the extension ".awk". The script has been working more than six years without an error, because the line with the value "9" in the example always exists. Since a few weeks, this entry doesn’t exist anymore in the input data. Because of this, the error occurred.
I have solved the problem by sorting the input files alphabetically, join the two files and sort them over again with a different key. Now it works. Thanks for your help.


Best regards

ET
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top