Re: File sorting question
From: Stephane CHAZELAS (stephane_chazelas_at_yahoo.fr)
Date: 05/13/03
- Next message: engineer: "line by line reading of the lines in list"
- Previous message: Tapani Tarvainen: "Re: deleting space between words"
- In reply to: Barry Margolin: "Re: File sorting question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 13 May 2003 18:34:02 GMT
Barry Margolin wrote:
> In article <7fcfe796.0305131000.2f8158ee@posting.google.com>,
> Nik <ndodnnn@yahoo.com> wrote:
[...]
>>P|3AAAFFR |01-OCT-1977|N|C| 237290| |CAD
>>P|3AAAFFR |01-FEB-1978|N|C| 271750| |CAD
>>
>>The sorting criteria is as follows: First, based on the second field
>>(such as 3BLEE1E) and second based on the third field ( a date field).
>>I know ksh sort can handle dates in this format but how do I specify
>>that in conjuction with the primary sorting criteria.
[...]
> sort -t'|' -k 2,2 -k 3,3<option> filename
>
> where <option> is the type option that causes it to do date sorting
> (Solaris sort apparently doesn't implement this, so I can't find the option
> in my man page).
GNU sort has the -M option (for month names):
sort -t'|' -k2,2 -k3.8,3n -k3.4,3.6M -k3.1,3.2n
With POSIX sorts, you'll need to change the month name into
something "sortable":
awk -F- '{
print index("JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC",$2)"|"$0}' \
| sort -t\| -k3,3 -k4.8,4n -k1,1n -k4.1,4.2n | cut -d\| -f2-
-- Stéphane
- Next message: engineer: "line by line reading of the lines in list"
- Previous message: Tapani Tarvainen: "Re: deleting space between words"
- In reply to: Barry Margolin: "Re: File sorting question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|