tags:

views:

26

answers:

2

I would like to reorder a whole file by ascending time order.

file.txt looks like this:

a 12.24 text

a 1.45 text

b 5.12 text

i would like it to look like this

a 1.45 text

b 5.12 text

a 12.24 text

Thanks in advance

A: 

Use the sort linux programme, not awk. Precisely:

sort -n -k 2 <filename>
mbq
To clarify, the difference between -n and -g is explained here: http://stackoverflow.com/questions/1255782/whats-the-difference-between-general-numeric-sort-and-numeric-sort-options-i .
mbq
+2  A: 

The sort command may fit your needs better than awk.

# sort -gk 2 test.txt 
a 1.45 text
b 5.12 text
a 12.24 text

-g compares them as numbers instead of strings. And -k 2 sorts on the second column.

Robert Wohlfarth