LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   complex sort question (https://www.linuxquestions.org/questions/linux-newbie-8/complex-sort-question-887586/)

yaniv1 06-21-2011 12:59 PM

complex sort question
 
hi all

I am getting a files with the format below from my application.
the format of the file names are <app name>_<version #>_<sn>_<name>

e.g

log_0.7.90.1_00010_black.txt
log_0.7.70.1_00010_silver.txt
log_0.7.80.1_00010_gold.txt
log_0.7.80.1_00020_blue.txt
log_0.7.80.1_00030_green.txt
log_0.7.80.1_00040_red.txt


how can i sort these files according to version number and its serial number
(i'm using Bash)
thank a lot
Yaniv

zer0signal 06-21-2011 01:16 PM

ls |sort -n

is that what you are looking for?

Tinkster 06-21-2011 02:00 PM

Quote:

Originally Posted by yaniv1 (Post 4391987)
hi all

I am getting a files with the format below from my application.
the format of the file names are <app name>_<version #>_<sn>_<name>

e.g

log_0.7.90.1_00010_black.txt
log_0.7.70.1_00010_silver.txt
log_0.7.80.1_00010_gold.txt
log_0.7.80.1_00020_blue.txt
log_0.7.80.1_00030_green.txt
log_0.7.80.1_00040_red.txt


how can i sort these files according to version number and its serial number
(i'm using Bash)
thank a lot
Yaniv



Code:

sort -t_ -k2,3 file
log_0.7.70.1_00010_silver.txt
log_0.7.80.1_00010_gold.txt
log_0.7.80.1_00020_blue.txt
log_0.7.80.1_00030_green.txt
log_0.7.80.1_00040_red.txt
log_0.7.90.1_00010_black.txt

?


Cheers,
Tink

yaniv1 06-21-2011 02:41 PM

thanks

grail 06-22-2011 12:43 AM

How about:
Code:

ls | sort -V


All times are GMT -5. The time now is 10:23 AM.