can Perl Sort do this, unix sort breaks on it (muliple spaces as demiliter)

Discussion in 'Perl Misc' started by colin_lyse, Feb 2, 2005.

  1. colin_lyse

    colin_lyse Guest

    runing Sun Unix 5.8 on Sun-Fire-15000

    i have a small file (20k) that looks like the following. some fields have 1
    space between them, others 2, others more. (. = space)

    00290..S.....33.XS798............SUB.......SUB ACTIVE 19971202
    00090..S.... 69KV..TSS30 TR LTC TR2 ACTIVE 20050201
    00135..S.... 69KV..TSS30 TRLTC TR1 ACTIVE 20050201

    the problem is that when i do the following

    sort +2 -3 it works the 3rd the list is correctly sorted in the third column.
    however, if I want to sort on the 4 colum and do

    sort +4 -5 it does not work (see example above), it sorts by the 4th column
    only in relation to the 3rd column (x goes first because of the 33), howve i
    think it might be related to the 1 vs. 2 spaces.

    I though about replacing the spaces with tabs, however some of the fields have
    spaces within them leading to problems with alignment.

    i also tried
    sort -n -k 5,5 -k 4,4 -k 6,6 but that didn't work only if i stoped after
    field 3

    It seems like the problem is that after field 3 there are differing amounts of
    space between fields .


    Can Perl Sort do this, new to perl. any help greated appreciated.
     
    colin_lyse, Feb 2, 2005
    #1
    1. Advertising

  2. colin_lyse

    Tore Aursand Guest

    Re: can Perl Sort do this, unix sort breaks on it (muliple spacesas demiliter)

    colin_lyse wrote:
    > [...]
    > Can Perl Sort do this, new to perl. any help greated appreciated.


    Yes, Perl can help you;

    perldoc -f sort
    perldoc -q sort


    --
    Tore Aursand <>
    "I know not with what weapons World War 3 will be fought, but World War
    4 will be fought with sticks and stones." (Albert Einstein)
     
    Tore Aursand, Feb 3, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ying

    muliple datagrids on one page.

    Ying, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    391
  2. Darrel

    updating muliple records

    Darrel, Oct 29, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    454
    Darrel
    Oct 30, 2004
  3. Tomasz Chmielewski

    [CSS] how can I show spaces as spaces?

    Tomasz Chmielewski, Sep 5, 2009, in forum: HTML
    Replies:
    21
    Views:
    1,635
    Jan C. Faerber
    Sep 10, 2009
  4. Tomasz Chmielewski

    how can I show spaces as spaces, part 2

    Tomasz Chmielewski, Sep 9, 2009, in forum: HTML
    Replies:
    14
    Views:
    893
    Jan C. Faerber
    Sep 10, 2009
  5. Jose Luis

    Perl sort different from unix sort

    Jose Luis, Mar 3, 2011, in forum: Perl Misc
    Replies:
    3
    Views:
    372
    Steve C
    Mar 3, 2011
Loading...

Share This Page