Re: Numerically sorted arguments (in shell)

Liste des GroupesRevenir à cu shell 
Sujet : Re: Numerically sorted arguments (in shell)
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shell
Date : 16. Jun 2024, 11:48:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4mcda$99f$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 16.06.2024 06:56, Lawrence D'Oliveiro wrote:
On Sun, 16 Jun 2024 05:11:29 +0200, Janis Papanagnou wrote:
 
I don't know of this feature in Perl or Python; please provide some hint
if there is a feature like the one I need. Some code samples for
demonstration of your point are also welcome.
 
Python solution:
 
    import re
 
    items = \
        [
            "P1.HTM", "P10.HTM", "P11.HTM", "P2.HTM", "P3.HTM",
            "P4.HTM", "P5.HTM", "P6.HTM", "P7.HTM", "P8.HTM", "P9.HTM",
        ]
 
    print(items)
 
    print \
      (
        sorted
          (
            items,
            key = lambda f :
                tuple
                  (
                    (lambda : p, lambda : int(p))[i % 2 != 0]()
                        for i, p in enumerate(re.split("([0-9]+)", f))
                  )
          )
      )
 
output:
 
    ['P1.HTM', 'P10.HTM', 'P11.HTM', 'P2.HTM', 'P3.HTM', 'P4.HTM', 'P5.HTM', 'P6.HTM', 'P7.HTM', 'P8.HTM', 'P9.HTM']
    ['P1.HTM', 'P2.HTM', 'P3.HTM', 'P4.HTM', 'P5.HTM', 'P6.HTM', 'P7.HTM', 'P8.HTM', 'P9.HTM', 'P10.HTM', 'P11.HTM']
 

Thanks. Though I'm not familiar with Python to understand that code;
it's too far from any language I've been using.

The (for me) interesting question, though, is; how does it solve the
task I had been addressing? - For convenience I reiterate one main
application...

I want from my shell command line interface call a viewer (or any
other application) with a list of files. If in shell I do, e.g.,

  viewer P*.HTM

the list gets sorted lexicographically. How would the main function
look like that I could embed in my call to make a numerically sorted
list. Say, something like, for example,

  viewer $( p_sort P*.HTM )

where p_sort would be the Python code. - Note: this is no appropriate
solution since it would anyway not work correctly for file names with
embedded blanks and newlines. I just want to get a closer understanding
how you think this would be usable in shell (or from shell). Thanks.

Janis


Date Sujet#  Auteur
14 Jun 24 * Numerically sorted arguments (in shell)46Janis Papanagnou
15 Jun 24 +* Re: Numerically sorted arguments (in shell)2Axel Reichert
15 Jun 24 i`- Re: Numerically sorted arguments (in shell)1Janis Papanagnou
16 Jun 24 +* Re: Numerically sorted arguments (in shell)20Lawrence D'Oliveiro
16 Jun 24 i`* Re: Numerically sorted arguments (in shell)19Janis Papanagnou
16 Jun 24 i +* Re: Numerically sorted arguments (in shell)14Lawrence D'Oliveiro
16 Jun 24 i i`* Re: Numerically sorted arguments (in shell)13Janis Papanagnou
16 Jun 24 i i +* Re: Numerically sorted arguments (in shell)4Helmut Waitzmann
17 Jun 24 i i i+- Re: Numerically sorted arguments (in shell)1Janis Papanagnou
18 Jun 24 i i i`* Re: Numerically sorted arguments (in shell)2Geoff Clare
19 Jun 24 i i i `- Re: Numerically sorted arguments (in shell)1Helmut Waitzmann
17 Jun 24 i i `* Re: Numerically sorted arguments (in shell)8Lawrence D'Oliveiro
17 Jun 24 i i  `* Re: Numerically sorted arguments (in shell)7Janis Papanagnou
17 Jun 24 i i   `* Re: Numerically sorted arguments (in shell)6Lawrence D'Oliveiro
17 Jun 24 i i    `* Re: Numerically sorted arguments (in shell)5Janis Papanagnou
18 Jun 24 i i     `* Re: Numerically sorted arguments (in shell)4Lawrence D'Oliveiro
18 Jun 24 i i      +- Re: Numerically sorted arguments (in shell)1Kenny McCormack
18 Jun 24 i i      +- Re: Numerically sorted arguments (in shell)1Janis Papanagnou
19 Jun 24 i i      `- Re: Numerically sorted arguments (in shell)1Kaz Kylheku
16 Jun 24 i `* Re: Numerically sorted arguments (in shell)4Eric Pozharski
17 Jun 24 i  `* Re: Numerically sorted arguments (in shell)3Janis Papanagnou
18 Jun 24 i   `* Re: Numerically sorted arguments (in shell)2Eric Pozharski
19 Jun 24 i    `- Re: Numerically sorted arguments (in shell)1Janis Papanagnou
18 Jun 24 +* Re: Numerically sorted arguments (in shell)5Chris Elvidge
18 Jun 24 i`* Re: Numerically sorted arguments (in shell)4Janis Papanagnou
18 Jun 24 i `* Re: Numerically sorted arguments (in shell)3Chris Elvidge
18 Jun 24 i  `* Re: Numerically sorted arguments (in shell)2Janis Papanagnou
18 Jun 24 i   `- Re: Numerically sorted arguments (in shell)1Janis Papanagnou
18 Jun 24 `* Re: Numerically sorted arguments (in shell)18Janis Papanagnou
19 Jun 24  `* Re: Numerically sorted arguments (in shell)17Chris Elvidge
19 Jun 24   `* Re: Numerically sorted arguments (in shell)16Janis Papanagnou
19 Jun 24    `* Re: Numerically sorted arguments (in shell)15Chris Elvidge
20 Jun 24     +* Re: Numerically sorted arguments (in shell)11vallor
20 Jun 24     i+- Re: Numerically sorted arguments (in shell)1Janis Papanagnou
20 Jun 24     i+* Re: Numerically sorted arguments (in shell)6Janis Papanagnou
21 Jun 24     ii`* Re: Numerically sorted arguments (in shell)5vallor
21 Jun 24     ii `* Re: Numerically sorted arguments (in shell)4Lawrence D'Oliveiro
21 Jun 24     ii  `* Re: Numerically sorted arguments (in shell)3vallor
21 Jun 24     ii   `* Re: Numerically sorted arguments (in shell)2Lawrence D'Oliveiro
21 Jun 24     ii    `- Re: Numerically sorted arguments (in shell)1Kenny McCormack
21 Jun 24     i`* Re: Numerically sorted arguments (in shell)3Chris Elvidge
24 Jun 24     i `* Is 'ls -v' the Final Solution? (Was: Numerically sorted arguments (in shell))2Kenny McCormack
24 Jun 24     i  `- Re: Is 'ls -v' the Final Solution? (Was: Numerically sorted arguments (in shell))1Janis Papanagnou
20 Jun 24     `* Re: Numerically sorted arguments (in shell)3Janis Papanagnou
24 Jun 24      `* Re: Numerically sorted arguments (in shell)2Chris Elvidge
24 Jun 24       `- Re: Numerically sorted arguments (in shell)1Janis Papanagnou

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal