Operating System - HP-UX
1827724 Members
2856 Online
109968 Solutions
New Discussion

Re: Sort by numeric value

 
SOLVED
Go to solution
Ed Hon
Regular Advisor

Sort by numeric value

When I run du and pipe it to sort -k 1,1 the results are ordered by collating sequence. Is there a way of ordering it by numeric value, e.g. 123 would appear after 24? Thanks.
3 REPLIES 3
Mike Williams_3
Advisor
Solution

Re: Sort by numeric value

du | sort -n -k 1,1
James R. Ferguson
Acclaimed Contributor

Re: Sort by numeric value

Ed:

Add the '-n' flag to your sort.

...JRF...
Steven Sim Kok Leong
Honored Contributor

Re: Sort by numeric value

Hi,

The -n option in sort allows you to sort by numeric value.

If you wish to sort by increasing value:

# du | sort -n

If you wish to sort by decreasing value:

# du | sort -r -n

Hope this helps. Regards.

Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com