Re: sort by 2nd and 3rd fields

From: Dale Hagglund (dale.hagglund_at_gmail.com)
Date: 06/11/05

  • Next message: Dale DeRemer: "sftp syntax"
    Date: Sat, 11 Jun 2005 08:21:50 GMT
    
    

        Harry> But the folllowing will screw up the 2nd (major sort) column.
        Harry> sort -t- -n -k2,2 -k3,3

    The -n option applies to all the fields, so the second field gets
    sorted numerically as well as the third field. Unfortunately, since
    none of the values in field 2 are numeric, all the fields compare as
    equal.

    You can attach a flag to each field selector as follows:

            $ sort -t- -k2,2 -k3,3n

    The trailing "n" on on the final argument applies numeric sorting to
    just the third field of the data. On your original sample input, this
    command gives:

            TYPE1-Apple-1
            TYPE1-Apple-2
            TYPE1-Apple-7a
            TYPE1-Apple-8
            TYPE2-Apple-10
            TYPE2-Apple-12
            TYPE1-Apple-13
            TYPE2-Apple-14
            TYPE2-Apple-15
            TYPE2-Apple-17
            TYPE1-Apple-19
            TYPE1-Orange-29
            TYPE1-Orange-35
            TYPE1-Orange-38
            TYPE1-Orange-45

    I don't think it will always do the right thing, though, with fields
    like "7a" and so on because they are not strictly numeric. You'll
    have to experiment with your dataset to make sure things work as
    desired.

    Dale.


  • Next message: Dale DeRemer: "sftp syntax"

    Relevant Pages

    • Re: data all in column 1
      ... always the second field, third line is third field, etc? ... Sub testme01() ... >> Dave Peterson ...
      (microsoft.public.excel.misc)
    • Determine Column Width and Bound Column
      ... How Do I determine Column width in a combobox. ... The first field SHipId not to be shown ... Second Field is the Company Name ... Third Field is the Address ...
      (microsoft.public.access.forms)
    • Re: Ascending Sort Problem
      ... "PC Datasheet" wrote: ... > In the second field, ... > In the third field, ... But when I sort I get the following, ...
      (microsoft.public.access.queries)
    • How to update a field with value from 2 calculated fields (dates)?
      ... The second field contains date when last check was done ... The third field is the one that needs to ... Do I need a condition in the validation rule in the ... or should I have an expression in queries? ...
      (microsoft.public.access.queries)
    • Updating a field with calculated dates from other field
      ... The second field contains date when last check was done ... The third field is the one that needs to ... Do I need a condition in the validation rule in the ... or should I have an expression in queries? ...
      (microsoft.public.access.tablesdbdesign)

    Loading