Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Q: Are we not men? A: We are Vaxen.


comp / comp.unix.shell / Re: Numerically sorted arguments (in shell)

SubjectAuthor
* Numerically sorted arguments (in shell)Janis Papanagnou
+* Re: Numerically sorted arguments (in shell)Axel Reichert
|`- Re: Numerically sorted arguments (in shell)Janis Papanagnou
+* Re: Numerically sorted arguments (in shell)Lawrence D'Oliveiro
|`* Re: Numerically sorted arguments (in shell)Janis Papanagnou
| +* Re: Numerically sorted arguments (in shell)Lawrence D'Oliveiro
| |`* Re: Numerically sorted arguments (in shell)Janis Papanagnou
| | +* Re: Numerically sorted arguments (in shell)Helmut Waitzmann
| | |+- Re: Numerically sorted arguments (in shell)Janis Papanagnou
| | |`* Re: Numerically sorted arguments (in shell)Geoff Clare
| | | `- Re: Numerically sorted arguments (in shell)Helmut Waitzmann
| | `* Re: Numerically sorted arguments (in shell)Lawrence D'Oliveiro
| |  `* Re: Numerically sorted arguments (in shell)Janis Papanagnou
| |   `* Re: Numerically sorted arguments (in shell)Lawrence D'Oliveiro
| |    `* Re: Numerically sorted arguments (in shell)Janis Papanagnou
| |     `* Re: Numerically sorted arguments (in shell)Lawrence D'Oliveiro
| |      +- Re: Numerically sorted arguments (in shell)Kenny McCormack
| |      +- Re: Numerically sorted arguments (in shell)Janis Papanagnou
| |      `- Re: Numerically sorted arguments (in shell)Kaz Kylheku
| `* Re: Numerically sorted arguments (in shell)Eric Pozharski
|  `* Re: Numerically sorted arguments (in shell)Janis Papanagnou
|   `* Re: Numerically sorted arguments (in shell)Eric Pozharski
|    `- Re: Numerically sorted arguments (in shell)Janis Papanagnou
+* Re: Numerically sorted arguments (in shell)Chris Elvidge
|`* Re: Numerically sorted arguments (in shell)Janis Papanagnou
| `* Re: Numerically sorted arguments (in shell)Chris Elvidge
|  `* Re: Numerically sorted arguments (in shell)Janis Papanagnou
|   `- Re: Numerically sorted arguments (in shell)Janis Papanagnou
`* Re: Numerically sorted arguments (in shell)Janis Papanagnou
 `* Re: Numerically sorted arguments (in shell)Chris Elvidge
  `* Re: Numerically sorted arguments (in shell)Janis Papanagnou
   `* Re: Numerically sorted arguments (in shell)Chris Elvidge
    +* Re: Numerically sorted arguments (in shell)vallor
    |+- Re: Numerically sorted arguments (in shell)Janis Papanagnou
    |+* Re: Numerically sorted arguments (in shell)Janis Papanagnou
    ||`* Re: Numerically sorted arguments (in shell)vallor
    || `* Re: Numerically sorted arguments (in shell)Lawrence D'Oliveiro
    ||  `* Re: Numerically sorted arguments (in shell)vallor
    ||   `* Re: Numerically sorted arguments (in shell)Lawrence D'Oliveiro
    ||    `- Re: Numerically sorted arguments (in shell)Kenny McCormack
    |`* Re: Numerically sorted arguments (in shell)Chris Elvidge
    | `* Is 'ls -v' the Final Solution? (Was: Numerically sorted arguments (in shell))Kenny McCormack
    |  `- Re: Is 'ls -v' the Final Solution? (Was: Numerically sorted arguments (in shell)Janis Papanagnou
    `* Re: Numerically sorted arguments (in shell)Janis Papanagnou
     `* Re: Numerically sorted arguments (in shell)Chris Elvidge
      `- Re: Numerically sorted arguments (in shell)Janis Papanagnou

Pages:12
Subject: Re: Numerically sorted arguments (in shell)
From: Eric Pozharski
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Tue, 18 Jun 2024 14:54 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: apple.universe@posteo.net (Eric Pozharski)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Tue, 18 Jun 2024 14:54:58 +0000
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <slrnv737u2.4m9.apple.universe@freight.zombinet>
References: <v4grk8$2pp51$1@dont-email.me> <v4l5p1$3lqic$10@dont-email.me>
<v4ll54$3sd11$1@dont-email.me>
<slrnv6ua1b.qfh.apple.universe@freight.zombinet>
<v4okm3$h4cs$1@dont-email.me>
Injection-Date: Tue, 18 Jun 2024 19:33:08 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="73abf3db35217ed140a46c6d34a84731";
logging-data="1546600"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lD/SVOZCU/GSpXnf4XKC9"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:+u+/NMbatcEsMKwIgOI95JpvK4o=
View all headers

with <v4okm3$h4cs$1@dont-email.me> Janis Papanagnou wrote:
> On 16.06.2024 20:00, Eric Pozharski wrote:
>> with <v4ll54$3sd11$1@dont-email.me> Janis Papanagnou wrote:

*SKIP* [ 20 lines 3 levels deep]
>> That being said, as a result of cross-pollination, something similar
>> might be in ksh too. I can't say where to dig through
>> ksh-documentation.
>
> Well, I don't know of any in Ksh. (That's my problem.)

Is it because oh-my-bad documentation or ksh seeks minimal feature-set?

p.s. Lack of features is a feature by itself, there's that.

--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

Subject: Re: Numerically sorted arguments (in shell)
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Wed, 19 Jun 2024 00:18 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Wed, 19 Jun 2024 02:18:50 +0200
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <v4t85c$1jp56$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4l5p1$3lqic$10@dont-email.me>
<v4ll54$3sd11$1@dont-email.me>
<slrnv6ua1b.qfh.apple.universe@freight.zombinet>
<v4okm3$h4cs$1@dont-email.me>
<slrnv737u2.4m9.apple.universe@freight.zombinet>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 19 Jun 2024 02:18:53 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b330dbc07241088e3a3cc72690d3a87d";
logging-data="1696934"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zN4f5hgRPHGXSkaVbqkho"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:uF3kGJ51XDCVLoavtRNOHQ29H0c=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <slrnv737u2.4m9.apple.universe@freight.zombinet>
View all headers

On 18.06.2024 16:54, Eric Pozharski wrote:
> with <v4okm3$h4cs$1@dont-email.me> Janis Papanagnou wrote:
>> On 16.06.2024 20:00, Eric Pozharski wrote:
>>> with <v4ll54$3sd11$1@dont-email.me> Janis Papanagnou wrote:

[ zsh's glob qualifier for numerically sorted glob expansion ]

> *SKIP* [ 20 lines 3 levels deep]
>>> That being said, as a result of cross-pollination, something similar
>>> might be in ksh too. I can't say where to dig through
>>> ksh-documentation.
>>
>> Well, I don't know of any in Ksh. (That's my problem.)
>
> Is it because oh-my-bad documentation or ksh seeks minimal feature-set?

Ksh has really a lot features. But not this ["basic" (sort of)] one.

(Well, I might as well have just missed it in the docs, but there's
also the Bolsky/Korn book where I didn't see it. And I'm using that
shell so long. And I've also got no hints yet.)

> p.s. Lack of features is a feature by itself, there's that.

Lacking features is certainly no feature of Ksh. ;-)

Janis

Subject: Re: Numerically sorted arguments (in shell)
From: Helmut Waitzmann
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Wed, 19 Jun 2024 00:22 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nn.throttle@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Wed, 19 Jun 2024 02:22:59 +0200
Organization: A noiseless patient Spider
Lines: 53
Sender: Helmut Waitzmann <12f7e638@mail.de>
Message-ID: <835xu5lr18.fsf@helmutwaitzmann.news.arcor.de>
References: <v4grk8$2pp51$1@dont-email.me> <v4l5p1$3lqic$10@dont-email.me>
<v4ll54$3sd11$1@dont-email.me> <v4lra6$3t7b2$2@dont-email.me>
<v4mcda$99f$1@dont-email.me>
<83sexcll5x.fsf@helmutwaitzmann.news.arcor.de>
<6bb8kk-pks.ln1@ID-313840.user.individual.net>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Date: Wed, 19 Jun 2024 02:28:13 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="6deb5e3df5134f40e156a0539e605b64";
logging-data="1699936"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xgX6qfUKRFWRrFu78mpc1JF30aUdBgv8="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Cancel-Lock: sha1:l+J10/JwkUd4b+E8xl6XU2Hx49s=
sha1:BOdolzlTDoEMl7Hy7DqYzzU9Neg=
Mail-Copies-To: nobody
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
View all headers

Geoff Clare <geoff@clare.See-My-Signature.invalid>:
> Helmut Waitzmann wrote:
>
>> If ‘p_sort’ is designed to output the sorted file names
>> separated by an ASCII NUL character rather than a newline
>> then, using the GNU version of ‘xargs’, one can feed that
>> output into ‘xargs’:
>>
>>
>> {
>> p_sort P*.HTM 3<&- |
>> xargs --null --no-run-if-empty -- sh -c \
>> 'exec 0<&3 3<&- "$@"' sh \
>> viewer
>> } 3<&0
>
> NUL as a record separator is also supported by several other
> versions of xargs, and it is in the recently released
> POSIX.1-2024 standard.
>

I'm glad to read that.  I didn't know either.

> In all of those it is specified with -0, so using -0 is more
> portable than the GNU-specific --null.
>

Yes, of course:  If ‘-0’ is in the POSIX standard, it is
preferable over ‘--null’.

> POSIX.1-2024 also has -r although I think that's not as widely
> supported in current xargs implementations as -0. It should
> become better supported over time, though, so again I would
> suggest using -r rather than --no-run-if-empty for better future
> portability.
>

I didn't know, that ‘-0’ as well as ‘-r’ are more widely
available (with the same semantics) than just in the GNU
version.  To minimize the risk of having a ‘xargs’ version, which
by accident uses the options ‘-0’ or ‘-r’ with different
semantics than GNU ‘xargs’ does, I preferred the long options (in
particular ‘--no-run-if-empty’) over the short.

Subject: Re: Numerically sorted arguments (in shell)
From: Kaz Kylheku
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Wed, 19 Jun 2024 01:05 UTC
References: 1 2 3 4 5 6 7 8 9 10
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Wed, 19 Jun 2024 01:05:20 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <20240618180416.382@kylheku.com>
References: <v4grk8$2pp51$1@dont-email.me> <v4l5p1$3lqic$10@dont-email.me>
<v4ll54$3sd11$1@dont-email.me> <v4lra6$3t7b2$2@dont-email.me>
<v4mcda$99f$1@dont-email.me> <v4oid0$gnmb$1@dont-email.me>
<v4ol9m$h7ir$1@dont-email.me> <v4onso$hmlh$1@dont-email.me>
<v4opho$i1r1$1@dont-email.me> <v4rgc5$18eq9$7@dont-email.me>
Injection-Date: Wed, 19 Jun 2024 03:05:20 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a089f22f6620d85d02f1b703c80c4bae";
logging-data="1711380"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19pTBLT0pB5Vk4boRBEHYGQUuls0tBiv5g="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:8hm92V0i8WFLgECLJoDEglvQZ3M=
View all headers

On 2024-06-18, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Mon, 17 Jun 2024 09:44:55 +0200, Janis Papanagnou wrote:
>
>> IOW; I'd have to learn Python completely to understand your code and get
>> the details properly.
>
> I give you a fish, you eat for a day. You learn to fish, you eat for a
> lifetime.

You fall into the Python trap, and eat shit for a lifetime.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Subject: Re: Numerically sorted arguments (in shell)
From: Chris Elvidge
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Wed, 19 Jun 2024 12:40 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris@x550c.mshome.net (Chris Elvidge)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Wed, 19 Jun 2024 13:40:28 +0100
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <v4ujjt$1vjpg$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 19 Jun 2024 14:40:29 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3373f7cc4ee03ab826d8717382aeee3f";
logging-data="2084656"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/G1a5m6vlE8kgRtumzb5zX/CnGz09Kx2Q="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:XPH2kqviakR7u5qDunP53Uk8ntQ=
In-Reply-To: <v4sena$1eqki$1@dont-email.me>
Content-Language: en-GB
View all headers

On 18/06/2024 at 18:04, Janis Papanagnou wrote:
> I've just tried a Unix tools based solution (with sed, sort, cut).
>
> Up to and including the line containing 'shuf' is data generation,
> the rest (starting with 'sed') extracts and sorts the data. I've
> written it for TWO numeric sort keys (see printf format specifier)
>
> for (( i=1; i<=50; i++ )) do for (( j=2; j<=120; j+=3 )) do printf
> "a%db%dc.txt\n" i j done done | shuf |
>
> sed 's/[^0-9]*\([0-9]\+\)[^0-9]*\([0-9]\+\)[^0-9]*/\1\t\2\t&/' | sort
> -t$'\t' -k1n -k2n | cut -f3-
>
> For just one numeric argument this can be simplified (shorter sed
> pattern, simpler sort -n command), and for more than two numeric
> fields it can be modified to dynamically construct the sed pattern,
> the sort option list, and the cut parameter, once at the beginning;
> that way we could have a tool for arbitrary amounts of numeric keys
> in the file name.
>
> Note: this program doesn't handle pathological filenames (newlines).
>
> Janis
>
>
If you're happy not handling pathological filenames:

for (( i=1; i<=50; i++ )); do for (( j=2; j<=120; j+=3 )); do touch
"a${i}b${j}c.txt"; done; done
to create the files.

exnums() { j="$(sed 's/[^[:digit:]]\+/ /g' <<<"$@")"; printf '%s%s\n'
"$j" "$@"; }
function replaces all non-digit sequences with a space, prints digit
sequence(s) and original input.

for i in *; do exnums "$i"; done | sort -k1n -k2n -k3n -k4n | awk
'{print $NF}'
sort doesn't seem to care how many -k you use, fields separated with space.
awk prints the last field of the input.

This "seems" to work with all manner of filenames from PNN.htm (as your
original sequence) to p323dc45g12.htm, p324dc45g12.htm, p333dc45g12.htm
Seems to work in ksh, too.

--
Chris Elvidge, England
TAR IS NOT A PLAYTHING

Subject: Re: Numerically sorted arguments (in shell)
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Wed, 19 Jun 2024 13:11 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Wed, 19 Jun 2024 15:11:27 +0200
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <v4ule0$200am$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 19 Jun 2024 15:11:28 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4b708d1a279efe9cda7a957a2de8b2c6";
logging-data="2097494"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/M2I6q/SZrfffSZTW9pcxS"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:/AVcCo+FYLgAFSWXTBTonvA5HtA=
In-Reply-To: <v4ujjt$1vjpg$1@dont-email.me>
View all headers

On 19.06.2024 14:40, Chris Elvidge wrote:
> On 18/06/2024 at 18:04, Janis Papanagnou wrote:
>> I've just tried a Unix tools based solution (with sed, sort, cut).
>> [...]
>> [...], and for more than two numeric
>> fields it can be modified to dynamically construct the sed pattern,
>> the sort option list, and the cut parameter, once at the beginning;
>> that way we could have a tool for arbitrary amounts of numeric keys in
>> the file name.
>>
>> Note: this program doesn't handle pathological filenames (newlines).
>>
>
> If you're happy not handling pathological filenames:

Well, typically I can indeed ignore them. But it's better of course
to avoid situations where processing is compromised by such names.

>
> for (( i=1; i<=50; i++ )); do for (( j=2; j<=120; j+=3 )); do touch
> "a${i}b${j}c.txt"; done; done
> to create the files.
>
> exnums() { j="$(sed 's/[^[:digit:]]\+/ /g' <<<"$@")"; printf '%s%s\n'
> "$j" "$@"; }
> function replaces all non-digit sequences with a space, prints digit
> sequence(s) and original input.
>
> for i in *; do exnums "$i"; done | sort -k1n -k2n -k3n -k4n | awk
> '{print $NF}'
> sort doesn't seem to care how many -k you use, fields separated with space.
> awk prints the last field of the input.
>
> This "seems" to work with all manner of filenames from PNN.htm (as your
> original sequence) to p323dc45g12.htm, p324dc45g12.htm, p333dc45g12.htm
> Seems to work in ksh, too.

I tried the approach I outlined above... (here just echo'ing the
created parts)...

N=${1:-1}
sed_a="[^0-9]*\([0-9]\+\)[^0-9]*"
sed_r="\1\t"
sort_a="-k1n"
for (( n=2; n<=N; n++ ))
do
sed_a+="\([0-9]\+\)[^0-9]*"
sed_r+="\\${n}\t"
sort_a+=" -k${n}n"
done
cut_a="-f$((N+1))-"

echo "# The following commands would be connected by pipes:"
echo "sed 's/${sed_a}/${sed_r}&/'"
echo "sort -t$'\t' ${sort_a}"
echo "cut ${cut_a}"

Janis

Subject: Re: Numerically sorted arguments (in shell)
From: Chris Elvidge
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Wed, 19 Jun 2024 15:06 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris@x550c.mshome.net (Chris Elvidge)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Wed, 19 Jun 2024 16:06:37 +0100
Organization: A noiseless patient Spider
Lines: 89
Message-ID: <v4us5u$21bu3$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me> <v4ule0$200am$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 19 Jun 2024 17:06:39 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="aae83bf3651d16a5aa72ca69b4003e5a";
logging-data="2142147"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+oDeXyN6hwE1KmV894paRcvZZQ0ITWPg="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:mkCEYMGl5lCRUx1s/f4aDt4ALCQ=
Content-Language: en-GB
In-Reply-To: <v4ule0$200am$1@dont-email.me>
View all headers

On 19/06/2024 at 14:11, Janis Papanagnou wrote:
> On 19.06.2024 14:40, Chris Elvidge wrote:
>> On 18/06/2024 at 18:04, Janis Papanagnou wrote:
>>> I've just tried a Unix tools based solution (with sed, sort, cut).
>>> [...]
>>> [...], and for more than two numeric
>>> fields it can be modified to dynamically construct the sed pattern,
>>> the sort option list, and the cut parameter, once at the beginning;
>>> that way we could have a tool for arbitrary amounts of numeric keys in
>>> the file name.
>>>
>>> Note: this program doesn't handle pathological filenames (newlines).
>>>
>>
>> If you're happy not handling pathological filenames:
>
> Well, typically I can indeed ignore them. But it's better of course
> to avoid situations where processing is compromised by such names.
>
>>
>> for (( i=1; i<=50; i++ )); do for (( j=2; j<=120; j+=3 )); do touch
>> "a${i}b${j}c.txt"; done; done
>> to create the files.
>>
>> exnums() { j="$(sed 's/[^[:digit:]]\+/ /g' <<<"$@")"; printf '%s%s\n'
>> "$j" "$@"; }
>> function replaces all non-digit sequences with a space, prints digit
>> sequence(s) and original input.
>>
>> for i in *; do exnums "$i"; done | sort -k1n -k2n -k3n -k4n | awk
>> '{print $NF}'
>> sort doesn't seem to care how many -k you use, fields separated with space.
>> awk prints the last field of the input.
>>
>> This "seems" to work with all manner of filenames from PNN.htm (as your
>> original sequence) to p323dc45g12.htm, p324dc45g12.htm, p333dc45g12.htm
>> Seems to work in ksh, too.
>
> I tried the approach I outlined above... (here just echo'ing the
> created parts)...
>
>
> N=${1:-1}
> sed_a="[^0-9]*\([0-9]\+\)[^0-9]*"
> sed_r="\1\t"
> sort_a="-k1n"
> for (( n=2; n<=N; n++ ))
> do
> sed_a+="\([0-9]\+\)[^0-9]*"
> sed_r+="\\${n}\t"
> sort_a+=" -k${n}n"
> done
> cut_a="-f$((N+1))-"
>
> echo "# The following commands would be connected by pipes:"
> echo "sed 's/${sed_a}/${sed_r}&/'"
> echo "sort -t$'\t' ${sort_a}"
> echo "cut ${cut_a}"
>
>
> Janis
>

Your way is still restricted to filenames with a known number of sets of
digits, though (AFAICS). I.e. you pass N rather than finding it.

But it takes a long time to do it my way, a call to sed for each
filename, so I tried to cut down the time taken to do this and came up with:

bash: exnums() { shopt -s extglob; j="${@//+([^[:digit:]])/ }"; printf
'%s%s\n' "$j" "$@"; }

ksh: exnums() { j="${@//+([^[:digit:]])/ }"; printf '%s%s\n' "$j" "$@"; }

ksh seems to do the extglob needed for bash natively.

removing the sed calls from exnum changes the time taken from 37 secs to
under 1 sec with 2000+ files
ksh is faster than bash, ksh 50% of the bash time taken.

Substituting a tab for the replacement space in j= and -t$'\t' in sort
would seem to allow spaces in filenames, too, as you originally had it.

--
Chris Elvidge, England
SUBSTITUTE TEACHERS ARE NOT SCABS

Subject: Re: Numerically sorted arguments (in shell)
From: vallor
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Wed, 19 Jun 2024 23:45 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vallor@cultnix.org (vallor)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Wed, 19 Jun 2024 23:45:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 101
Message-ID: <v4vqib$21g0v$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me> <v4ule0$200am$1@dont-email.me>
<v4us5u$21bu3$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 20 Jun 2024 01:45:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="baf3932e2944e3ee1162c1dae94de446";
logging-data="2146335"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+N7PfitdinzcZ6opYoFPh/"
User-Agent: Pan/0.159 (Vovchansk; 873418b; Linux-6.9.5)
Cancel-Lock: sha1:Rn7bv14WGgsX4JvIv+wRas5xInE=
X-Face: \}2`P"_@pS86<'EM:'b.Ml}8IuMK"pV"?FReF$'c.S%u9<Q#U*4QO)$l81M`{Q/n
XL'`91kd%N::LG:=*\35JS0prp\VJN^<s"b#bff@fA7]5lJA.jn,x_d%Md$,{.EZ
View all headers

On Wed, 19 Jun 2024 16:06:37 +0100, Chris Elvidge <chris@x550c.mshome.net>
wrote in <v4us5u$21bu3$1@dont-email.me>:

> On 19/06/2024 at 14:11, Janis Papanagnou wrote:
>> On 19.06.2024 14:40, Chris Elvidge wrote:
>>> On 18/06/2024 at 18:04, Janis Papanagnou wrote:
>>>> I've just tried a Unix tools based solution (with sed, sort, cut).
>>>> [...]
>>>> [...], and for more than two numeric fields it can be modified to
>>>> dynamically construct the sed pattern, the sort option list, and the
>>>> cut parameter, once at the beginning; that way we could have a tool
>>>> for arbitrary amounts of numeric keys in the file name.
>>>>
>>>> Note: this program doesn't handle pathological filenames (newlines).
>>>>
>>>>
>>> If you're happy not handling pathological filenames:
>>
>> Well, typically I can indeed ignore them. But it's better of course to
>> avoid situations where processing is compromised by such names.
>>
>>
>>> for (( i=1; i<=50; i++ )); do for (( j=2; j<=120; j+=3 )); do touch
>>> "a${i}b${j}c.txt"; done; done to create the files.
>>>
>>> exnums() { j="$(sed 's/[^[:digit:]]\+/ /g' <<<"$@")"; printf '%s%s\n'
>>> "$j" "$@"; }
>>> function replaces all non-digit sequences with a space, prints digit
>>> sequence(s) and original input.
>>>
>>> for i in *; do exnums "$i"; done | sort -k1n -k2n -k3n -k4n | awk
>>> '{print $NF}'
>>> sort doesn't seem to care how many -k you use, fields separated with
>>> space.
>>> awk prints the last field of the input.
>>>
>>> This "seems" to work with all manner of filenames from PNN.htm (as
>>> your original sequence) to p323dc45g12.htm, p324dc45g12.htm,
>>> p333dc45g12.htm Seems to work in ksh, too.
>>
>> I tried the approach I outlined above... (here just echo'ing the
>> created parts)...
>>
>>
>> N=${1:-1}
>> sed_a="[^0-9]*\([0-9]\+\)[^0-9]*"
>> sed_r="\1\t"
>> sort_a="-k1n"
>> for (( n=2; n<=N; n++ ))
>> do
>> sed_a+="\([0-9]\+\)[^0-9]*"
>> sed_r+="\\${n}\t" sort_a+=" -k${n}n"
>> done cut_a="-f$((N+1))-"
>>
>> echo "# The following commands would be connected by pipes:"
>> echo "sed 's/${sed_a}/${sed_r}&/'"
>> echo "sort -t$'\t' ${sort_a}"
>> echo "cut ${cut_a}"
>>
>>
>> Janis
>>
>>
> Your way is still restricted to filenames with a known number of sets of
> digits, though (AFAICS). I.e. you pass N rather than finding it.
>
> But it takes a long time to do it my way, a call to sed for each
> filename, so I tried to cut down the time taken to do this and came up
> with:
>
> bash: exnums() { shopt -s extglob; j="${@//+([^[:digit:]])/ }"; printf
> '%s%s\n' "$j" "$@"; }
>
> ksh: exnums() { j="${@//+([^[:digit:]])/ }"; printf '%s%s\n' "$j" "$@";
> }
>
> ksh seems to do the extglob needed for bash natively.
>
> removing the sed calls from exnum changes the time taken from 37 secs to
> under 1 sec with 2000+ files ksh is faster than bash, ksh 50% of the
> bash time taken.
>
> Substituting a tab for the replacement space in j= and -t$'\t' in sort
> would seem to allow spaces in filenames, too, as you originally had it.

I finally remembered which tool has "versionsort(3)" -- it's ls:

$ ls -1
test10.txt
test1.txt
test2.txt

$ ls -v -1
test1.txt
test2.txt
test10.txt

Does that help?

--
-v

Subject: Re: Numerically sorted arguments (in shell)
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Thu, 20 Jun 2024 04:34 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Thu, 20 Jun 2024 06:34:02 +0200
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <v50bfs$2dqkh$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me> <v4ule0$200am$1@dont-email.me>
<v4us5u$21bu3$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 20 Jun 2024 06:34:04 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1a9a410acf435c06a905868c6b72f695";
logging-data="2550417"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18urvnODnfH9qJsv2REhJFv"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:5a7xqX5zr+bmvHYes+vESQf+KtE=
In-Reply-To: <v4us5u$21bu3$1@dont-email.me>
X-Enigmail-Draft-Status: N1110
View all headers

On 19.06.2024 17:06, Chris Elvidge wrote:
> On 19/06/2024 at 14:11, Janis Papanagnou wrote:
>>> [...]
>>
>> I tried the approach I outlined above... (here just echo'ing the
>> created parts)...
>>
>>
>> N=${1:-1}
>> sed_a="[^0-9]*\([0-9]\+\)[^0-9]*"
>> sed_r="\1\t"
>> sort_a="-k1n"
>> for (( n=2; n<=N; n++ ))
>> do
>> sed_a+="\([0-9]\+\)[^0-9]*"
>> sed_r+="\\${n}\t"
>> sort_a+=" -k${n}n"
>> done
>> cut_a="-f$((N+1))-"
>>
>> echo "# The following commands would be connected by pipes:"
>> echo "sed 's/${sed_a}/${sed_r}&/'"
>> echo "sort -t$'\t' ${sort_a}"
>> echo "cut ${cut_a}"
>>
>
> Your way is still restricted to filenames with a known number of sets of
> digits, though (AFAICS). I.e. you pass N rather than finding it.

Yes. Above is just a codified version of the method I described
(thus also the echo's). Whether it's provided as parameter N or
obtained, say, from one of the files is left unanswered. Myself
I'd prefer some solution where even file sets with mixed amounts
of numerical parts may be used; thus being able to handle lists
that are named like chapters, like 1, 1.1, 1.2, ..., 5.3.3

Slowly and continuously approaching the goal... :-)

Janis

> [...]

Subject: Re: Numerically sorted arguments (in shell)
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Thu, 20 Jun 2024 04:43 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Thu, 20 Jun 2024 06:43:13 +0200
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <v50c12$2dtrs$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me> <v4ule0$200am$1@dont-email.me>
<v4us5u$21bu3$1@dont-email.me> <v4vqib$21g0v$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 20 Jun 2024 06:43:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1a9a410acf435c06a905868c6b72f695";
logging-data="2553724"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+P88fag8qvwv4GOgQ1Rw5h"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:OgRLLW24Yo90Ju+AlqXIQp1nYKA=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <v4vqib$21g0v$1@dont-email.me>
View all headers

On 20.06.2024 01:45, vallor wrote:
>> [...]
>
> I finally remembered which tool has "versionsort(3)" -- it's ls:
>
> $ ls -1
> test10.txt
> test1.txt
> test2.txt
>
> $ ls -v -1
> test1.txt
> test2.txt
> test10.txt
>
> Does that help?

Sure, thanks. - Just remember that it's a non-standard option. But
for my GNU environment it's certainly a usable part of the solution.
It seems to also handle multiple numeric components as desired (as
versions usually have)

$ ls | shuf | xargs ls -v
1 1.2 1.11 2.1 2.10 10.1 10.10 11.1
1.1 1.10 2 2.2 2.11 10.2 10.11 11.2

Janis

Subject: Re: Numerically sorted arguments (in shell)
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Thu, 20 Jun 2024 04:58 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Thu, 20 Jun 2024 06:58:11 +0200
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <v50ct5$2e2lp$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me> <v4ule0$200am$1@dont-email.me>
<v4us5u$21bu3$1@dont-email.me> <v4vqib$21g0v$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 20 Jun 2024 06:58:14 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1a9a410acf435c06a905868c6b72f695";
logging-data="2558649"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18n2hX0mW6N7OyVs8JLtgB1"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:w7px4sjxJ6rR8JBQbHM0bC8v28w=
In-Reply-To: <v4vqib$21g0v$1@dont-email.me>
X-Enigmail-Draft-Status: N1110
View all headers

On 20.06.2024 01:45, vallor wrote:
>
> I finally remembered which tool has "versionsort(3)" -- [...]

It's a pity that this function is a GNU extension, otherwise
it could be used to implement the desired function in shells
(ksh, bash) as an additional globbing option (like the zsh
glob qualifier) or a new 'set' option to control the sorting.

Janis

Subject: Re: Numerically sorted arguments (in shell)
From: vallor
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Thu, 20 Jun 2024 22:16 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vallor@cultnix.org (vallor)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Thu, 20 Jun 2024 22:16:42 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <v529oa$2lkuv$4@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me> <v4ule0$200am$1@dont-email.me>
<v4us5u$21bu3$1@dont-email.me> <v4vqib$21g0v$1@dont-email.me>
<v50ct5$2e2lp$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 21 Jun 2024 00:16:42 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a414156ff05630fd2d65fa3742155188";
logging-data="2806751"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+eVF/BVNKV4A1WQWDeO4YV"
User-Agent: Pan/0.159 (Vovchansk; 873418b; Linux-6.9.5)
Cancel-Lock: sha1:2Wpwy/RNAD90kWwhCT0f1RbLzQU=
X-Face: \}2`P"_@pS86<'EM:'b.Ml}8IuMK"pV"?FReF$'c.S%u9<Q#U*4QO)$l81M`{Q/n
XL'`91kd%N::LG:=*\35JS0prp\VJN^<s"b#bff@fA7]5lJA.jn,x_d%Md$,{.EZ
View all headers

On Thu, 20 Jun 2024 06:58:11 +0200, Janis Papanagnou
<janis_papanagnou+ng@hotmail.com> wrote in <v50ct5$2e2lp$1@dont-email.me>:

> On 20.06.2024 01:45, vallor wrote:
>>
>> I finally remembered which tool has "versionsort(3)" -- [...]
>
> It's a pity that this function is a GNU extension, otherwise it could be
> used to implement the desired function in shells (ksh, bash) as an
> additional globbing option (like the zsh glob qualifier) or a new 'set'
> option to control the sorting.
>
> Janis

I just posted a python program to comp.lang.python that sorts parameters
using strverscmp(3). It also shell-escapes the (common) IFS characters.

--
-v

Subject: Re: Numerically sorted arguments (in shell)
From: Lawrence D'Oliv
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Fri, 21 Jun 2024 03:37 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Fri, 21 Jun 2024 03:37:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <v52sif$3019v$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me> <v4ule0$200am$1@dont-email.me>
<v4us5u$21bu3$1@dont-email.me> <v4vqib$21g0v$1@dont-email.me>
<v50ct5$2e2lp$1@dont-email.me> <v529oa$2lkuv$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 21 Jun 2024 05:37:51 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="66b3929645a80745d97b68595a297468";
logging-data="3147071"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wcmQy/E6JZwXAfePn4xWP"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:akl+CM2OdGRaH74HNI73uoz7leg=
View all headers

On Thu, 20 Jun 2024 22:16:42 -0000 (UTC), vallor wrote:

> I just posted a python program to comp.lang.python that sorts parameters
> using strverscmp(3).

I already posted a snippet here which sorts strings containing any number
of decimal-numerical segments.

Subject: Re: Numerically sorted arguments (in shell)
From: vallor
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Fri, 21 Jun 2024 04:20 UTC
References: 1 2 3 4 5 6 7 8 9
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vallor@cultnix.org (vallor)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Fri, 21 Jun 2024 04:20:47 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <v52v2v$2q8of$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me> <v4ule0$200am$1@dont-email.me>
<v4us5u$21bu3$1@dont-email.me> <v4vqib$21g0v$1@dont-email.me>
<v50ct5$2e2lp$1@dont-email.me> <v529oa$2lkuv$4@dont-email.me>
<v52sif$3019v$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 21 Jun 2024 06:20:47 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a414156ff05630fd2d65fa3742155188";
logging-data="2958095"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19V+qnrfLJar+7uXR3riY99"
User-Agent: Pan/0.159 (Vovchansk; 873418b; Linux-6.9.5)
Cancel-Lock: sha1:ZCb8QbXFep22QBQSo80s8pn7SYw=
X-Face: \}2`P"_@pS86<'EM:'b.Ml}8IuMK"pV"?FReF$'c.S%u9<Q#U*4QO)$l81M`{Q/n
XL'`91kd%N::LG:=*\35JS0prp\VJN^<s"b#bff@fA7]5lJA.jn,x_d%Md$,{.EZ
View all headers

On Fri, 21 Jun 2024 03:37:51 -0000 (UTC), Lawrence D'Oliveiro
<ldo@nz.invalid> wrote in <v52sif$3019v$1@dont-email.me>:

> On Thu, 20 Jun 2024 22:16:42 -0000 (UTC), vallor wrote:
>
>> I just posted a python program to comp.lang.python that sorts
>> parameters using strverscmp(3).
>
> I already posted a snippet here which sorts strings containing any
> number of decimal-numerical segments.

While I can't speak for others, something about the way you
went about that rubbed me the wrong way.

More on-topic, I did post the code in comp.lang.python with a request
for comments. Sometimes I feel like Manfred Mann's "The Demolition Man",
where "I kill conversation as I walk into the room." It is no exception
there, even though it would seem to be a good example of using a C binding
with python's sort function. (Having very little experience with python
programming, I couldn't really say with confidence -- but nobody has
complained so far.)

I wrote it to learn something about python, and to be a (q&d) shell
utility that someone might find useful, possibly Janis. Since
this is the shell newsgroup, and not the python programming
newsgroup, I think discussing the finer points of python
programming really don't belong here. YMMV.

I'm also put-off by "snip-and-snark" Usenet. I know a few people who
do that to tick-off the person they're conversing with. I'm guilty
of doing that from time to time, but I hope it's only when
the situation warrants it. If my opinion matters: it's a bad habit to
do so by default.

--
-v

Subject: Re: Numerically sorted arguments (in shell)
From: Lawrence D'Oliv
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Fri, 21 Jun 2024 05:41 UTC
References: 1 2 3 4 5 6 7 8 9 10
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Fri, 21 Jun 2024 05:41:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <v533pd$318so$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me> <v4ule0$200am$1@dont-email.me>
<v4us5u$21bu3$1@dont-email.me> <v4vqib$21g0v$1@dont-email.me>
<v50ct5$2e2lp$1@dont-email.me> <v529oa$2lkuv$4@dont-email.me>
<v52sif$3019v$1@dont-email.me> <v52v2v$2q8of$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 21 Jun 2024 07:41:02 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="66b3929645a80745d97b68595a297468";
logging-data="3187608"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18RMY/887Pz+FoDdXCSS6im"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:Bv5JtChSn89bnxlmd81qUH/c0gQ=
View all headers

On Fri, 21 Jun 2024 04:20:47 -0000 (UTC), vallor wrote:

> While I can't speak for others, something about the way you went about
> that rubbed me the wrong way.

I solved the specific problem that seems to be the stumbling block, and
left the rest as an exercise for the reader.

That wasn’t up to your particular high standards? You know what you can
do.

Subject: Re: Numerically sorted arguments (in shell)
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Fri, 21 Jun 2024 07:31 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Fri, 21 Jun 2024 07:31:53 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <v53a99$2gk17$1@news.xmission.com>
References: <v4grk8$2pp51$1@dont-email.me> <v52sif$3019v$1@dont-email.me> <v52v2v$2q8of$1@dont-email.me> <v533pd$318so$1@dont-email.me>
Injection-Date: Fri, 21 Jun 2024 07:31:53 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2641959"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

In article <v533pd$318so$1@dont-email.me>,
Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
>On Fri, 21 Jun 2024 04:20:47 -0000 (UTC), vallor wrote:
>
>> While I can't speak for others, something about the way you went about
>> that rubbed me the wrong way.
>
>I solved the specific problem that seems to be the stumbling block, and
>left the rest as an exercise for the reader.
>
>That wasnt up to your particular high standards? You know what you can
>do.

Somebody's fee-fees are getting more than a little butt-hurt...

Sad.

--
Those on the right constantly remind us that America is not a
democracy; now they claim that Obama is a threat to democracy.

Subject: Re: Numerically sorted arguments (in shell)
From: Chris Elvidge
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Fri, 21 Jun 2024 13:21 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris@slack15-a.mshome.net (Chris Elvidge)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Fri, 21 Jun 2024 14:21:43 +0100
Organization: A noiseless patient Spider
Lines: 107
Message-ID: <7cbgkkx149.ln2@slack15-a.local.uk>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me> <v4ule0$200am$1@dont-email.me>
<v4us5u$21bu3$1@dont-email.me> <v4vqib$21g0v$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 21 Jun 2024 16:15:04 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c06db5df11e65ee6eaae1fc58fbfa72f";
logging-data="3373600"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jBRa/B95c5a+N3XB5vF+nXV3rFCtNLiQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1
Cancel-Lock: sha1:9FtRmt4Esm0kxlV9ipGmmK4ho64=
Content-Language: en-GB
In-Reply-To: <v4vqib$21g0v$1@dont-email.me>
View all headers

On 20/06/24 00:45, vallor wrote:
> On Wed, 19 Jun 2024 16:06:37 +0100, Chris Elvidge <chris@x550c.mshome.net>
> wrote in <v4us5u$21bu3$1@dont-email.me>:
>
>> On 19/06/2024 at 14:11, Janis Papanagnou wrote:
>>> On 19.06.2024 14:40, Chris Elvidge wrote:
>>>> On 18/06/2024 at 18:04, Janis Papanagnou wrote:
>>>>> I've just tried a Unix tools based solution (with sed, sort, cut).
>>>>> [...]
>>>>> [...], and for more than two numeric fields it can be modified to
>>>>> dynamically construct the sed pattern, the sort option list, and the
>>>>> cut parameter, once at the beginning; that way we could have a tool
>>>>> for arbitrary amounts of numeric keys in the file name.
>>>>>
>>>>> Note: this program doesn't handle pathological filenames (newlines).
>>>>>
>>>>>
>>>> If you're happy not handling pathological filenames:
>>>
>>> Well, typically I can indeed ignore them. But it's better of course to
>>> avoid situations where processing is compromised by such names.
>>>
>>>
>>>> for (( i=1; i<=50; i++ )); do for (( j=2; j<=120; j+=3 )); do touch
>>>> "a${i}b${j}c.txt"; done; done to create the files.
>>>>
>>>> exnums() { j="$(sed 's/[^[:digit:]]\+/ /g' <<<"$@")"; printf '%s%s\n'
>>>> "$j" "$@"; }
>>>> function replaces all non-digit sequences with a space, prints digit
>>>> sequence(s) and original input.
>>>>
>>>> for i in *; do exnums "$i"; done | sort -k1n -k2n -k3n -k4n | awk
>>>> '{print $NF}'
>>>> sort doesn't seem to care how many -k you use, fields separated with
>>>> space.
>>>> awk prints the last field of the input.
>>>>
>>>> This "seems" to work with all manner of filenames from PNN.htm (as
>>>> your original sequence) to p323dc45g12.htm, p324dc45g12.htm,
>>>> p333dc45g12.htm Seems to work in ksh, too.
>>>
>>> I tried the approach I outlined above... (here just echo'ing the
>>> created parts)...
>>>
>>>
>>> N=${1:-1}
>>> sed_a="[^0-9]*\([0-9]\+\)[^0-9]*"
>>> sed_r="\1\t"
>>> sort_a="-k1n"
>>> for (( n=2; n<=N; n++ ))
>>> do
>>> sed_a+="\([0-9]\+\)[^0-9]*"
>>> sed_r+="\\${n}\t" sort_a+=" -k${n}n"
>>> done cut_a="-f$((N+1))-"
>>>
>>> echo "# The following commands would be connected by pipes:"
>>> echo "sed 's/${sed_a}/${sed_r}&/'"
>>> echo "sort -t$'\t' ${sort_a}"
>>> echo "cut ${cut_a}"
>>>
>>>
>>> Janis
>>>
>>>
>> Your way is still restricted to filenames with a known number of sets of
>> digits, though (AFAICS). I.e. you pass N rather than finding it.
>>
>> But it takes a long time to do it my way, a call to sed for each
>> filename, so I tried to cut down the time taken to do this and came up
>> with:
>>
>> bash: exnums() { shopt -s extglob; j="${@//+([^[:digit:]])/ }"; printf
>> '%s%s\n' "$j" "$@"; }
>>
>> ksh: exnums() { j="${@//+([^[:digit:]])/ }"; printf '%s%s\n' "$j" "$@";
>> }
>>
>> ksh seems to do the extglob needed for bash natively.
>>
>> removing the sed calls from exnum changes the time taken from 37 secs to
>> under 1 sec with 2000+ files ksh is faster than bash, ksh 50% of the
>> bash time taken.
>>
>> Substituting a tab for the replacement space in j= and -t$'\t' in sort
>> would seem to allow spaces in filenames, too, as you originally had it.
>
> I finally remembered which tool has "versionsort(3)" -- it's ls:
>
> $ ls -1
> test10.txt
> test1.txt
> test2.txt
>
> $ ls -v -1
> test1.txt
> test2.txt
> test10.txt
>
> Does that help?
>

I didn't realise it could work like that. Thanks.

--
Chris Elvidge
England

Subject: Is 'ls -v' the Final Solution? (Was: Numerically sorted arguments (in shell))
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Mon, 24 Jun 2024 13:22 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Is 'ls -v' the Final Solution? (Was: Numerically sorted arguments (in shell))
Date: Mon, 24 Jun 2024 13:22:28 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <v5bruk$2kl97$1@news.xmission.com>
References: <v4grk8$2pp51$1@dont-email.me> <v4us5u$21bu3$1@dont-email.me> <v4vqib$21g0v$1@dont-email.me> <7cbgkkx149.ln2@slack15-a.local.uk>
Injection-Date: Mon, 24 Jun 2024 13:22:28 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2774311"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

In article <7cbgkkx149.ln2@slack15-a.local.uk>,
....
>> I finally remembered which tool has "versionsort(3)" -- it's ls:
>>
>> $ ls -1
>> test10.txt
>> test1.txt
>> test2.txt
>>
>> $ ls -v -1
>> test1.txt
>> test2.txt
>> test10.txt
>>
>> Does that help?
>>
>
>I didn't realise it could work like that. Thanks.

To OP: Does "ls -v" meet your criteria?

--
Faced with the choice between changing one's mind and proving that there is
no need to do so, almost everyone gets busy on the proof.

- John Kenneth Galbraith -

Subject: Re: Is 'ls -v' the Final Solution? (Was: Numerically sorted arguments (in shell))
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 14:01 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Is 'ls -v' the Final Solution? (Was: Numerically sorted arguments
(in shell))
Date: Mon, 24 Jun 2024 16:01:03 +0200
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <v5bu70$vaas$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4us5u$21bu3$1@dont-email.me>
<v4vqib$21g0v$1@dont-email.me> <7cbgkkx149.ln2@slack15-a.local.uk>
<v5bruk$2kl97$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jun 2024 16:01:04 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="41527c1e8b8737ff56f892523a11e944";
logging-data="1026396"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18cvh13EODcVLnMx4q5sDui"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:1nUBZFCpN0i6OPbCfEwPikvdGXI=
In-Reply-To: <v5bruk$2kl97$1@news.xmission.com>
X-Enigmail-Draft-Status: N1110
View all headers

On 24.06.2024 15:22, Kenny McCormack wrote:
> In article <7cbgkkx149.ln2@slack15-a.local.uk>,
> ...
>>> I finally remembered which tool has "versionsort(3)" -- it's ls:
>>>
>>> $ ls -1
>>> test10.txt
>>> test1.txt
>>> test2.txt
>>>
>>> $ ls -v -1
>>> test1.txt
>>> test2.txt
>>> test10.txt
>>>
>>> Does that help?
>>>
>>
>> I didn't realise it could work like that. Thanks.
>
> To OP: Does "ls -v" meet your criteria?

Yes, at least partly. (Why are you asking?)

It meets it in the way that it's ready available and usable
as external command. It does not solve the shell internal
additional globbing feature (like in Zsh) that would be
nice and preferable.

In the quoted form as 'ls -vQ' some pathological filenames
are (seemingly) handled, but there's some hassle with the
quotes in the subsequent processing steps to expect (or so
I think). That's why an integrated form supported by shell
would IMO be an advantage; so that we could simply write

set -o numsortglob # <-- hypothetical shell feature
for f in version*.gz
do ...
done

At least the output from code like

for f in $(ls -vQ) ; do printf "'%s'\n" "$f" ; done

or

ls -vQ | while IFS= read -r f ; do printf "'%s'\n" "$f" ; done

indicates that there's still something to do, and without
the 'ls -Q' quotes the (pathological) newlines are an issue
(at least).

I think it's a typical problem that would best be solved
by a shell built-in feature. (External tools may take you
part of the road and probably with additional effort for
common subsets of the task but probably not bullet-proof.)

Janis

Subject: Re: Numerically sorted arguments (in shell)
From: Chris Elvidge
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 14:22 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris@x550c.mshome.net (Chris Elvidge)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Mon, 24 Jun 2024 15:22:24 +0100
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <v5bvf2$vhj8$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me> <v4ule0$200am$1@dont-email.me>
<v4us5u$21bu3$1@dont-email.me> <v50bfs$2dqkh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jun 2024 16:22:26 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="05ff251bd2344cdf4ef764bddc267408";
logging-data="1033832"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vOgYd4UJs60hCM+bvGjnYODUzs7whRZw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:plH9Jl2grutIbtDx7sXRRVW2WvI=
In-Reply-To: <v50bfs$2dqkh$1@dont-email.me>
Content-Language: en-GB
View all headers

On 20/06/2024 at 05:34, Janis Papanagnou wrote:
> On 19.06.2024 17:06, Chris Elvidge wrote:
>> On 19/06/2024 at 14:11, Janis Papanagnou wrote:
>>>> [...]
>>>
>>> I tried the approach I outlined above... (here just echo'ing the
>>> created parts)...
>>>
>>>
>>> N=${1:-1}
>>> sed_a="[^0-9]*\([0-9]\+\)[^0-9]*"
>>> sed_r="\1\t"
>>> sort_a="-k1n"
>>> for (( n=2; n<=N; n++ ))
>>> do
>>> sed_a+="\([0-9]\+\)[^0-9]*"
>>> sed_r+="\\${n}\t"
>>> sort_a+=" -k${n}n"
>>> done
>>> cut_a="-f$((N+1))-"
>>>
>>> echo "# The following commands would be connected by pipes:"
>>> echo "sed 's/${sed_a}/${sed_r}&/'"
>>> echo "sort -t$'\t' ${sort_a}"
>>> echo "cut ${cut_a}"
>>>
>>
>> Your way is still restricted to filenames with a known number of sets of
>> digits, though (AFAICS). I.e. you pass N rather than finding it.
>
> Yes. Above is just a codified version of the method I described
> (thus also the echo's). Whether it's provided as parameter N or
> obtained, say, from one of the files is left unanswered. Myself
> I'd prefer some solution where even file sets with mixed amounts
> of numerical parts may be used; thus being able to handle lists
> that are named like chapters, like 1, 1.1, 1.2, ..., 5.3.3
>
> Slowly and continuously approaching the goal... :-)
>
> Janis
>
>> [...]
>

Originally you said:
(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'?)

Does 'sort -V' help?
Seems to work with both spaces and newlines.

--
Chris Elvidge, England
NO ONE CARES WHAT MY DEFINITION OF "IS" IS

Subject: Re: Numerically sorted arguments (in shell)
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 15:22 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Numerically sorted arguments (in shell)
Date: Mon, 24 Jun 2024 17:22:00 +0200
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <v5c2uq$107jo$1@dont-email.me>
References: <v4grk8$2pp51$1@dont-email.me> <v4sena$1eqki$1@dont-email.me>
<v4ujjt$1vjpg$1@dont-email.me> <v4ule0$200am$1@dont-email.me>
<v4us5u$21bu3$1@dont-email.me> <v50bfs$2dqkh$1@dont-email.me>
<v5bvf2$vhj8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jun 2024 17:22:02 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="04364c5bb161db47f6d7f608c7a1aac1";
logging-data="1056376"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/pRsrqrrjsXtFfvUdu263S"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:6NQHems9kqXOE9Ejr1lJVg5HAWs=
In-Reply-To: <v5bvf2$vhj8$1@dont-email.me>
X-Enigmail-Draft-Status: N1110
View all headers

On 24.06.2024 16:22, Chris Elvidge wrote:
>>[...]
>
> Originally you said:
> (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'?)
>
> Does 'sort -V' help?
> Seems to work with both spaces and newlines.

Yes, that would help like 'ls -v' does (presuming it behaves similar;
I haven't extensively tried 'sort -V' yet). (But using 'ls | sort -V'
is not that terse like 'ls -v'.) The problem with both external tools
is (as outlined upthread) the post-processing of the tool-generated
list of data in shell context. So both tools take some burden from
me (the sorting aspect is simply covered by an option), but doesn't
help me how I can safely post-process the identified items. (A shell
built-in could natively better, i.e. simpler and more consistently,
address that.)

Janis

Pages:12

rocksolid light 0.9.8
clearnet tor