Re: File sorting question

From: Barry Margolin (barry.margolin_at_level3.com)
Date: 05/13/03


Date: Tue, 13 May 2003 18:10:23 GMT

In article <7fcfe796.0305131000.2f8158ee@posting.google.com>,
Nik <ndodnnn@yahoo.com> wrote:
>Hi all,
>
>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
external program.

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, barry.margolin@level3.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.


Relevant Pages

  • File sorting question
    ... I need a quick way to sort a file (ksh, awk, perl are all fine). ... The sorting criteria is as follows: First, based on the second field ...
    (comp.unix.shell)
  • Re: How to do pattern matching for multiple files in Perl
    ... I am new to Perl and know ksh better. ... And I was told that perl is faster than ksh. ... You can read its contents with the operator, see perldoc perlop. ... You can sort a list with the sort function, ...
    (comp.lang.perl.misc)
  • RE: [opensuse] OT: bash F1
    ... You should sort your result because ls garantees no particular order ... You don't need expr as long as you are using bash or ksh or zsh or ... In ksh you don't need to spawn a sub shell just to use printf just to ...
    (SuSE)
  • Re: C-shell login script
    ... It's fine for a login shell if you like that sort of ... Have you tried ksh? ... John Hasler ... Dancing Horse Hill ...
    (comp.os.linux.setup)
  • Re: Urgent: Need an integer for loop for renaming files
    ... > If you have ksh, a general solution to this sort of renaming problem is ...
    (comp.unix.shell)