3

I have a log file named a.log ! I want sort it by the fisrt field ! If two lines have the same field , the order will be original contens‘! contents:

 1. 101  c
 2. 100  b
 3. 100  a
 4. 2    d

I expect the result:

 1. 2    d
 2. 100  b
 3. 100  a
 4. 101  c

So i use this command!

sort -nt 't' -k 1 a.log 

But the result is :

 1. 2    d
 2. 100  a
 3. 100  b
 4. 101  c

Thanks very much!</p>

4

2 回答 2

7

You forgot to constrain the key fields. By default it uses until the end of the line.

sort -nst '\t' -k 1,1 0507.log
于 2012-05-15T02:33:24.547 回答
0

Take a peek at the man page for sort...

   `-n`, --numeric-sort

      compare according to string numerical value

So here is an example...

sort -n filename
于 2012-05-15T06:42:37.140 回答