1748111 Members
3341 Online
108758 Solutions
New Discussion юеВ

sort help

 
SOLVED
Go to solution
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 3
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...