ls help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ls help
# 1  
Old 03-13-2008
ls help

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
# 2  
Old 03-13-2008
ls -1 | sort -t '_' -k 2,2n

or

ls -1 | sort -n -t '_' +1

-anchal
# 3  
Old 03-13-2008
Code:
printf "%s\n" temp_*|sort -t_ -k2n

# 4  
Old 03-13-2008
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...
# 5  
Old 03-13-2008
If you have zsh:

Code:
set -- temp_*;print -l ${(on)@}

Otherwise:

Code:
printf "%s\n" ABC.tl_temp_*|sort -t_ -k3n

# 6  
Old 03-13-2008
Thanks buddy ,now that works fine....
I'll have to check how this command works ....
If u have time can u explani..
# 7  
Old 03-13-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question