Hi,
I have some files:
temp_1
temp_11
temp_123
temp_2
temp_22
temp_234
temp_3
temp_33
temp_345 and so on
I want a listing to be in following order....
temp_1
temp_2
temp_3
temp_11
temp_22
temp_33
temp_123
temp_234
temp_345
I am unable to do so using ls command.....can anyone help
clx
2
ls -1 | sort -t '_' -k 2,2n
or
ls -1 | sort -n -t '_' +1
-anchal
printf "%s\n" temp_*|sort -t_ -k2n
actually i have the files having names
ABC.tl_temp_52
TCE.tl_temp_53
and so on......i.e there are two underscore..
so the command fails there ...
it works fine with 1 underscore...
If you have zsh:
set -- temp_*;print -l ${(on)@}
Otherwise:
printf "%s\n" ABC.tl_temp_*|sort -t_ -k3n
Thanks buddy ,now that works fine....
I'll have to check how this command works ....
If u have time can u explani..
clx
7
in that case the numeric part is now 3rd field ( with _ as a delim )
so use
ls -1 | sort -t '_' -k 3,3n
or
ls -1 | sort -n -t '_' +2
Got it !! Thanks a lot....