Sujet : Re: Numerically sorted arguments (in shell)
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shellDate : 20. Jun 2024, 06:34:02
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v50bfs$2dqkh$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
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
[...]