Path: ...!2.eu.feeder.erje.net!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: 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: References: 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: X-Enigmail-Draft-Status: N1110 Bytes: 2475 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 > [...]