Liste des Groupes | Revenir à cu shell |
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:
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.
Les messages affichés proviennent d'usenet.