title: Join gives warning "file1 is not in sorted order"
body: <p>Was testing a legacy script in the new version of bash 4.1.2(1)-release
  , and encountered this warning in the console:</p>
  
  <pre><code>join: file 1 is not in sorted order
  join: file 2 is not in sorted order
  </code></pre>
  
  <p>I am quite sure that both of the files are sorted. The files actually merged properly.</p>
  
  <p>Below is the script:</p>
  
  <pre><code>cat $FILE1_PATH'.processed.1' | cut -d'|' -f4,8 | sort | uniq -u  &gt; $FILE1_PATH.'processed.2'
  cat $FILE2_PATH'.processed.1' | cut -d'|' -f1,8 | sort | uniq -u &gt; $FILE2_PATH.'processed.2'
  join -t$'|' -1 1 -2 1 $FILE1_PATH.'processed.2' $FILE2_PATH.'processed.2' &gt; $MERGEFILE_PATH
  </code></pre>
  
  <p>To job of this script : </p>
  
  <ol>
  <li>extract field 4 and 8 from file 1</li>
  <li>extract field 1 and 8 from file 2</li>
  <li>combine the extracted fields, using join key file1.field4 = file2.field1</li>
  <li>remove any duplicates.</li>
  </ol>
  
  <p>FILE1.processed.2 :</p>
  
  <pre><code>21VIANET GP INC|GOV
  ABN|ABN1
  ABN|ABN2
  ABOC|ABOC1
  ABOC|ABOC1
  ABOC|ABOC2
  ....
  </code></pre>
  
  <p>FILE2.processed.2 :</p>
  
  <pre><code>ABN|Banks
  ABOC|Pharmaceuticals
  GOV|Government Agency 
  ....
  </code></pre>
  
  <p>OUTPUT:</p>
  
  <pre><code>GOV|21VIANET GP INC|Government Agency
  ABN|ABN1|Banks
  ABN|ABN2|Banks
  ABOC|ABOC1|Pharmaceuticals
  ABOC|ABOC2|Pharmaceuticals  
  ....
  </code></pre>
  
  <p>Running the same script in the bash version 3.2.25(1)-release gives no warning. Any idea to solve the warning?</p>
  
  <p>UPDATE:
  Seems that the cause was caused by these lines in the input files...</p>
  
  <pre><code>ADBC|Banks 
  ADB|Banks
  </code></pre>
  
  <p>Join expects ADBC to be positioned after ADB, like below :</p>
  
  <pre><code>ADB|Banks
  ADBC|Banks
  </code></pre>
  
  <p>However I tried to change my sort script from sort -u to sort -t$'|' -k1 (sort based on the first field ) however still not working...</p>