Home > bash > join – file 1 is not in sorted order (Error)

join – file 1 is not in sorted order (Error)

Problem:
I had two sorted files that I needed to join but join kept on giving me the following error
join: file 1 is not in sorted order.

user@computer:~$less file1
1,0
2,0
3,0
4,0
5,0
6,0
7,0
8,0
9,0
10,0
user@computer:~$less file2
1,1701
2,59
3,6
4,1
5,1
user@computer:~$join -t"," -1 1 -2 1 -a 1 -e'0' -o '1.1,2.2' file1 file2
1,1701
2,59
3,6
4,1
5,1
6,0
7,0
8,0
9,0
join: file 1 is not in sorted order
10,0

Solution:
join –nocheck-order

user@computer:~$join --nocheck-order -t"," -1 1 -2 1 -a 1 -e'0' -o '1.1,2.2' file1 file2
1,1701
2,59
3,6
4,1
5,1
6,0
7,0
8,0
9,0
10,0

Source:
info join

NB:
This is the version of join I was using. The –nocheck-order option may not be available on earlier versions. You might not even get the error with older versions.

join (GNU coreutils) 8.5
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel.

Advertisements
Categories: bash
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: