Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix "sort" command help.... 1

Status
Not open for further replies.

Fozzeebear

Technical User
Oct 20, 2003
6
GB
I have a text file containing a list with four fields. I would like to sort numerically by the fourth field, so I am using:

sort +3n -n input > output.

My problem is that the fourth field actually contains numbers with exponents i.e 2.5e-05, and sort is only ordering things by the number before the decimal point. It is ignoring the exponent. Is it possible to sort things in the way I would like?

Any help will be much appreciated...
 
Well if you have GNU sort, then you have this option
Code:
`-g'
`--general-numeric-sort'
     Sort numerically, using the standard C function `strtod' to convert
     a prefix of each line to a double-precision floating point number.
     This allows floating point numbers to be specified in scientific
     notation, like `1.0e-34' and `10e100'.

If you don't have that, and the numbers are presented in a consistent form, say nnnnnn.neee (n for the number, e for the exponent), then you could try sorting by exponent first, then sort by numbers.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top