perl sort

Discussion in 'Perl Misc' started by Jan Burdil, Sep 22, 2006.

  1. Jan Burdil

    Jan Burdil Guest

    Hello,
    how can I replace * with some command like cat file, ls -l in line

    perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'

    Thank you
    Jan Burdil
     
    Jan Burdil, Sep 22, 2006
    #1
    1. Advertising

  2. Jan Burdil

    J. Gleixner Guest

    Jan Burdil wrote:
    > Hello,
    > how can I replace * with some command like cat file, ls -l in line
    >
    > perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'


    You'd use your editor, or your arrow keys, move the cursor to '*',
    remove '*', and insert whatever you like.

    Maybe explaining what you want to do and what you tried would get you a
    better answer.
     
    J. Gleixner, Sep 22, 2006
    #2
    1. Advertising

  3. Jan Burdil

    Ben Morrow Guest

    Quoth "Jan Burdil" <>:
    > Subject: perl sort


    Please use a sensible Subject. You question has nothing to do with
    sorting.

    > how can I replace * with some command like cat file, ls -l in line
    >
    > perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'


    You can skip the last "\n" by adding a -l to your commandline.
    You can skip the join by putting

    $, = "\n";

    before the print statement, though that's arguably no simpler in this
    case.

    Read the section on qx in perldoc perlop.

    Alternatively, you can probably do what you want from within Perl,
    without calling an external command.

    Ben

    --
    #!/bin/sh
    quine="echo 'eval \$quine' >> \$0; echo quined"
    eval $quine
    # []
     
    Ben Morrow, Sep 22, 2006
    #3
  4. Jan Burdil

    Guest

    Jan Burdil wrote:
    > how can I replace * with some command like cat file, ls -l in line
    > perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'


    perl -e 'print join "\n", sort { -M $b <=> -M $a } `ls -l`,"\n"'

    But I find it hard to believe you REALLY want to do that... that's
    nutty. There are far better ways to do that (either in Perl or using
    plain shell commands).

    --
    David Filmer (http://DavidFilmer.com)
     
    , Sep 22, 2006
    #4
  5. Jan Burdil

    Jan Burdil Guest

    when I try
    perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'
    bb
    xx
    aa
    Mail
    mail
    yy
    unrar
    tmp
    curl.txt
    abc

    my files are sorted by date. And I need to sort lines from curl command.
    curl ftp://1.1.1.1 give me
    -rw-r--r-- 1 honza users 414 Sep 22 12:16 curl.txt
    -rwx------ 1 honza users 52 May 31 21:54 bb
    drwx------ 2 honza users 512 Aug 22 10:54 mail

    And I would like the result to be sorted by date.

    I try replace <*> with command curl ftp://1.1.1.1 like this
    perl -e 'print join "\n", sort { -M $b <=> -M $a } `curl
    ftp://1.1.1.1`,"\n"'
    but this doesn't work

    Jan Burdil



    <> wrote in message
    news:...
    > Jan Burdil wrote:
    >> how can I replace * with some command like cat file, ls -l in line
    >> perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'

    >
    > perl -e 'print join "\n", sort { -M $b <=> -M $a } `ls -l`,"\n"'
    >
    > But I find it hard to believe you REALLY want to do that... that's
    > nutty. There are far better ways to do that (either in Perl or using
    > plain shell commands).
    >
    > --
    > David Filmer (http://DavidFilmer.com)
    >
     
    Jan Burdil, Sep 22, 2006
    #5
  6. Jan Burdil

    Guest

    Jan Burdil wrote:

    > my files are sorted by date. And I need to sort lines from curl command.
    > curl ftp://1.1.1.1 give me


    Somtimes the shell way is the easier way. for example:

    ls -l |sort -k 1.37

    (see also the -t flag of sort)

    --
    David Filmer (http://DavidFilmer.com)
     
    , Sep 23, 2006
    #6
  7. On 2006-09-22 22:21, Tad McClellan <> wrote:
    > Jan Burdil <> wrote:
    >> And I need to sort lines from curl command.
    >> curl ftp://1.1.1.1 give me
    >> -rw-r--r-- 1 honza users 414 Sep 22 12:16 curl.txt
    >> -rwx------ 1 honza users 52 May 31 21:54 bb
    >> drwx------ 2 honza users 512 Aug 22 10:54 mail
    >>
    >> And I would like the result to be sorted by date.

    [...]
    >> like this
    >> perl -e 'print join "\n", sort { -M $b <=> -M $a } `curl
    >> ftp://1.1.1.1`,"\n"'

    [...]
    >
    > You need to arrange for $a and $b to contain filenames,


    How would this help? He needs to sort lines which contain a text
    representation of a date by this date. -M doesn't do that, so he
    shouldn't use -M but extract the date from each line and convert it to a
    comparable value (e.g., seconds since the epoch, or yyyy-mm-ddThh:mm).
    HTTP::Date may be helpful.

    Another way might be to ditch curl in favour of Net::FTP. I haven't
    looked at it, but I expect it to contain a function to parse directory
    listings from FTP servers.

    hp


    --
    _ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
    |_|_) | Sysadmin WSR | > ist?
    | | | | Was sonst wäre der Sinn des Erfindens?
    __/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
     
    Peter J. Holzer, Sep 23, 2006
    #7
  8. Jan Burdil

    Jan Burdil Guest

    this command cort the output, but not good

    ls -l |sort -k 1.37
    drwx------ 2 honza users 512 Aug 22 10:54 mail
    -rwx------ 1 honza users 54 Jun 14 11:29 aa
    -rwx------ 1 honza users 832 Sep 5 19:35 yy
    -rwx------ 1 honza users 52 May 31 21:54 bb

    ....
    Jan Burdil


    <> wrote in message
    news:...
    > Jan Burdil wrote:
    >
    >> my files are sorted by date. And I need to sort lines from curl command.
    >> curl ftp://1.1.1.1 give me

    >
    > Somtimes the shell way is the easier way. for example:
    >
    > ls -l |sort -k 1.37
    >
    > (see also the -t flag of sort)
    >
    > --
    > David Filmer (http://DavidFilmer.com)
    >
     
    Jan Burdil, Sep 23, 2006
    #8
    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. nobody
    Replies:
    0
    Views:
    539
    nobody
    Jun 1, 2004
  2. JerryJ
    Replies:
    11
    Views:
    1,407
    Dave Moore
    Apr 28, 2004
  3. Navin
    Replies:
    1
    Views:
    705
    Ken Schaefer
    Sep 9, 2003
  4. colin_lyse
    Replies:
    1
    Views:
    153
    Tore Aursand
    Feb 3, 2005
  5. Jose Luis

    Perl sort different from unix sort

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

Share This Page