Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

sort help

SOLVED
Go to solution
Highlighted
Rinky
Advisor

sort help

Hi experts,

I have a comma separated file.
The fourth field in the file is date of the form: DD-MON-YYYY format.
I wanted the file sorted according to the fourth field.
DD : 01-31
sort -knr4 wont work.
sort +3 -4 also dint work..

Please help.
3 REPLIES
Steven E. Protter
Exalted Contributor

Re: sort help

Shalom,

From my new memory leak monitor.

CL="ps -o pid,args,sz,vsz | sort -nr -k 3,4| head -$NUM"


This sorts by field three then field 4.

All you need to do is get the field separator right.

I would suggest a combination of awk and sort.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor
Solution

Re: sort help

>I wanted the file sorted according to the fourth field.

You need to break up the fourth field into 3 fields with "." syntax.

>SEP: I would suggest a combination of awk and sort.

No need, sort(1) has enough horsepower:
sort -t, -k4.8n,4.11n -k4.4M,4.6M -k4.1n,4.2n file

Use the "." notation to get bytes within field 4. Use "M" to sort by months.
Rinky
Advisor

Re: sort help

Thanks Dennis..
It worked exactly as I wanted...