sort help (85 Views)
Reply
Advisor
Rinky
Posts: 27
Registered: ‎05-03-2007
Message 1 of 4 (85 Views)
Accepted Solution

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.
Please use plain text.
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 2 of 4 (85 Views)

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
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,746
Registered: ‎03-06-2006
Message 3 of 4 (85 Views)

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.
Please use plain text.
Advisor
Rinky
Posts: 27
Registered: ‎05-03-2007
Message 4 of 4 (85 Views)

Re: sort help

Thanks Dennis..
It worked exactly as I wanted...
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation