title: Linux shell and sort -t and -k
body: <p>I am using a Linux shell script to create 5-fold cross validation to movielens data.  Can anyone explain to me what:</p>
  
  <ol>
  <li><code>sort -k 1,1n</code> means?  I know it means start from column <code>1</code> and ends at <code>1n</code> but what does <code>1n</code> mean?</li>
  <li>My data is like <code>****::****::***</code>, that is to say, the separator is <code>::</code>, but neither "::" nor "::" work  for the <code>sort -t</code> option. Can you tell me what is the right way to set <code>::</code> as the separator? (<code>sort -t " "</code> means the separator is space; this works, but my file's separator is not space.)</li>
  </ol>
  
  
  
  <pre><code>trap `rm -f tmp.$$; exit 1` 1 2 15 # trap begin to execute the cmd in the quote when it meet signal 1,2 and 15
  batch=200000
  totalTuple=1000000
  #$$ is the process id
  for i in 1 2 3 4 5 #five fold cross validation,  train/test is one fold
  do
      head -`expr $i \* ${batch}` u.data | tail -`expr ${batch}` &gt; tmp.$$  # take the ith 1/5 block
      # expr return the cmd result as string
      sort -t"\:\:" -k 1,1n -k 2,2n tmp.$$ &gt; u$i.test
      #sort -k -k, --key=KEYDEF sort via a key; KEYDEF gives location and type
      #sort -t, --field-separator=SEP
      head -`expr \( $i - 1 \) \* ${batch}` u.data &gt; tmp.$$
      tail -`expr \( 5 - $i \) \* ${batch}` u.data &gt;&gt; tmp.$$
      sort -t"\:\:" -k 1,1n -k 2,2n tmp.$$ &gt; u$i.base
  done
  </code></pre>