well artist gave essentially a un*x golf solution. I'll recast it and comment on a couple tricks.

first 'echo */' (or print) is a good way of getting directories if you are using a posix shell.

% echo dir*/ | xargs -n1 | sort -rnt- -k2,3 | perl -lne 'print if $. = +=2'

the 'echo */ | xargs -n1' can be seen as a poor man's transpose. It is useful if you know your paths! spaces don't work directly ...and xargs understands some quoting

In the end it is safer to use:

% NL=' > ' % (IFS="$NL"; for i in dir*/; do echo $i; done) | > sort -rnt- -k2,3 | perl -lne 'print if $. ==2' % steph@ape (/home/stephan/t) % % cat dirdata dir-100-1 dir-100-10 dir-100-2 dir-100-9 dir-100-99 dir-2-1 dir-28-1 dir-29-1 dir-29-2 dir-30-1 dir-3-1 % steph@ape (/home/stephan/t) % % cat dirdata | sort -nt- -k2,3 dir-2-1 dir-3-1 dir-28-1 dir-29-1 dir-29-2 dir-30-1 dir-100-1 dir-100-10 dir-100-2 dir-100-9 dir-100-99 % steph@ape (/home/stephan/t) % % cat dirdata | sort -rnt- -k2,3 | perl -lne 'print if $. == 2' dir-100-9
cheers --stephan

In reply to Re: Command line file sorting by sgt
in thread Command line file sorting by swkronenfeld

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.