Sujet : Re: Numerically sorted arguments (in shell)
De : mail (at) *nospam* axel-reichert.de (Axel Reichert)
Groupes : comp.unix.shellDate : 15. Jun 2024, 15:56:22
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <8734peia2h.fsf@axel-reichert.de>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
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?
(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.
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.
Best regards
Axel