Deutsch English Français Italiano |
<v5bvf2$vhj8$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Chris Elvidge <chris@x550c.mshome.net> 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 Bytes: 2989 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