Re: File sorting question
From: Barry Margolin (barry.margolin_at_level3.com)
Date: Tue, 13 May 2003 18:10:23 GMT
In article <email@example.com>,
Nik <firstname.lastname@example.org> wrote:
>I need a quick way to sort a file (ksh, awk, perl are all fine).
>The file looks like this:
>P|3BLEE1E |01-JAN-2002|N|C| 2046284.28| |CAD
>P|3BLEE1E |01-APR-1999|N|C| 1787056.18| |CAD
>P|3BLEE1E |01-MAY-1999|N|C| 1750609.37| |CAD
>P|3BLEE1E |01-MAY-2001|N|C| 2331432.6| |CAD
>P|3BLEE1E |01-JUN-2001|N|C| 2308868.41| |CAD
>P|3BLEE1E |01-AUG-1977|N|C| 237115| |CAD
>P|3AAAFFR |01-MAY-2001|N|C| 2331432.6| |CAD
>P|3AAAFFR |01-SEP-1977|N|C| 237290| |CAD
>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.
What do you mean by "ksh sort"? sort isn't a shell built-in, it's an
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).
-- Barry Margolin, email@example.com Genuity Managed Services, a Level(3) Company, Woburn, MA *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups. Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.