I have multiple names that have the same prefix but the prefix is unknown.
I want to sort only by the digits in the name.
i.e
abcd_006-123
abcd_006-232
bbcd_w_006-112
so bbcd_w_006-112
should be the first
thanks
filenames
I have multiple names that have the same prefix but the prefix is unknown.
I want to sort only by the digits in the name.
i.e
abcd_006-123
abcd_006-232
bbcd_w_006-112
so bbcd_w_006-112
should be the first
thanks
Best Answer
With
zsh
, you could define a glob sorting function like:and then use it as:
There, the
n
glob qualifier turns thenumericglobsort
option for that one glob extension, ando+function
sorts based on the output (via$REPLY
) of thefunction
.print -rC1
prints its argumentsr
aw on1
c
olumn.Remember that if you use
ls
,ls
does sort the list of files before printing (alphabetically by default). With the GNU implementation ofls
, that sorting can be avoided with the-U
option:You can do something similar with
perl
with:Or to run a command on that list of files: