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 : 15. Jun 2024, 16:43:50
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4k9b8$3go8u$1@dont-email.me>
References : 1 2
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 15.06.2024 15:56, Axel Reichert wrote:
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
 
What I'm trying to do is iterating over files, say,
  P1.HTM P10.HTM P11.HTM P2.HTM P3.HTM P4.HTM P5.HTM P6.HTM P7.HTM
P8.HTM P9.HTM
in numerical order.
 
Could you employ printf to add leading zeros, sort lexicogpaphically and
then remove the zeros?

Something like this (not using printf but a more elementary method) is
actually what I'm currently doing. (It's not really complex but quite
some data fiddling I wanted to avoid. I have that in a script and it's
not a general solution but handles just simple cases like the sample
data above, which is 95% of my usages so it's okay for that but not
really satisfying for other or more general cases.)

To get the original name back I think I'd have to store the original
names along with the new names. (Which is something I've not yet done.)

 
(Ideally I'd also like to handle names with two numbers "A35P56.txt"
and irregular string components (lowercase, say, "page310ch1.txt"),
but that's just a nice-to-have. - I might make use of 'sort'?)
 
You did not yet mention what your final goal is with the numerically
sorted list.

The original application was that I simply wanted to sequentially skim
through a number of files.[*] In the past (where possible) I've just
renamed the files to let them have numbers of equal length (as noted
above). But the general task I envision is that I don't want to change
any name of data files but just be able to iterate over these files,
or list them numerically sorted (and without the known issues of \n
and blank handling).

I thought that a contemporary shell would probably support that but I
was astonished that (at least in ksh) it wasn't supported (as far as
I saw).[**]

 
In case this is in the end a renaming task, for this level of complexity
I would use the "wdired" mode of Emacs ("write directory edits") and use
regexes for search and replace. Or some other "multi-rename" tools from
the command line.

I've my own script to adjust numbers in files. But as said, I'd rather
want to iterate or sort, like the lexicographic ordering in ksh

  set -s page*.gif

(which in that example is anyway the default for wildcard patterns)
something similar for numeric argument setting (or pattern expansion)

  set --numerical page*.gif

To use that features more widely it would be nice if the wild-card
expansion could be controlled, say by

  set -o numerical

Well, maybe that all makes no sense and should be tackled differently?
But it's how it appears to me at the moment. (Feel free to enlighten
me. :-)

Janis

[*] I occasionally have this task; the last time was when I wanted to
read old typewriter documents that had been scanned page-wise as GIF
files.

[**] Yet I haven't checked Zsh; that shell supports some non-standard
modifiers in certain zsh-specific constructs, so it might possible it
has support for this requirement as well. (But Zsh is not the shell
I'm using so I'm primarily seeking for a Ksh solution or POSIX shell
workaround.)


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