Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Need help with the UNIX command below to sort the file by the following words, from major sort key to minor sort key: word 3, word 1, word 4. (words are separated by white spaces)

sort -t -k3 -k1 -k4 > newfile.txt doesnt work

share|improve this question

migrated from Mar 21 '13 at 10:56

This question came from our site for professional and enthusiast programmers.

Short answer is, get rid of the -t or specify -t" " or similar to specify a single character as your delimiter.

So: sort -k3 -k1 -k4 in.txt > newfile.txt

In detail...


one two three four
the quick brown fox
jumps over the lazy dog
pun poo three poor
one two three four five
the elegant brown zebra

bash cmd

  • You are sorting words, so just I'm showing how to specify the -d option for dictionary sort. You could use numeric sort with the -g option for other situations.
  • You want whitespace - this is what sort uses by default. Otherwise you'd need to use -t"," or similar.
  • So the cmd is:

    sort -k3,3d -k1,1d -k4,4d in.txt > newfile.txt


the quick brown fox
the elegant brown zebra
jumps over the lazy dog
one two three four
one two three four five
pun poo three poor
share|improve this answer
Thanx azhrei. That was fast. Btw what does the d argument stands for ? – user2180912 Mar 20 '13 at 3:53
explicit!!! Thanks – user2180912 Mar 20 '13 at 4:19
No worries. Welcome to StackOverflow! Don't forget to accept if this answers your question. – azhrei Mar 20 '13 at 4:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.