Re: File sorting question

From: Stephane CHAZELAS (stephane_chazelas_at_yahoo.fr)
Date: 05/13/03


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


Relevant Pages

  • Re: where does GiGi schedule so traditionally, whenever Saeed maintains the civic club very physical
    ... While probes furthermore preach punishments, ... sort at first the straight commissions. ... They are extracting subject to extreme, with blue, sort of lonely ... currently specify the agent. ...
    (sci.crypt)
  • Re: Access database records not sorted
    ... Just because you sort and display your data within Access ... Also you need to specify whether your code is using ADO or DAO. ... You'll obviously need to set the database path, table name, ...
    (microsoft.public.word.vba.general)
  • Re: Cohens paper on byte order
    ... function such as "sort" operates in order to have a complete specification. ... correctly when the sort algorithm is applied to a dataset in a one-pass ... to specify internal behavior of the algorithm in certain applications. ...
    (sci.crypt)
  • Re: ways to update PS files?
    ... multi-user access (without some sort of higher level manager) would ... In order for two users to have the data set allocated concurrently, they would have to specify DISP=SHR. ... For IBM-MAIN subscribe / signoff / archive access instructions, ... send email to listserv@xxxxxxxxxxx with the message: GET IBM-MAIN INFO ...
    (bit.listserv.ibm-main)
  • Sorting using TVM_SORTCHILDRENCB
    ... lParam As Long ... > I was wondering if there is any way to specify the sorting method used in ... > PS. I'm looking to sort so the following appears. ...
    (microsoft.public.vb.winapi)