LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-21-2011, 01:59 PM   #1
yaniv1
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Rep: Reputation: Disabled
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

Last edited by yaniv1; 06-21-2011 at 02:07 PM.
 
Old 06-21-2011, 02:16 PM   #2
zer0signal
Member
 
Registered: Oct 2010
Location: Cleveland
Distribution: Slackware, Fedora, RHEL (4,5), LFS 6.7, CentOS
Posts: 258

Rep: Reputation: 29
ls |sort -n

is that what you are looking for?
 
Old 06-21-2011, 03:00 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by yaniv1 View Post
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
 
Old 06-21-2011, 03:41 PM   #4
yaniv1
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
thanks
 
Old 06-22-2011, 01:43 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,254

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
How about:
Code:
ls | sort -V
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Complex GTK2 question - SourceView vargadanis Programming 1 10-25-2006 12:20 AM
ad-hoc connection (and internet sharing) between two linux boxes. A complex question. riccisit Linux - Wireless Networking 1 09-29-2005 10:02 AM
a very complex question about kernel?? back-off Slackware 11 09-11-2005 11:14 AM
complex question help needed ropeboardCEO Linux - Newbie 4 12-25-2004 01:02 AM
Sort of a question belkins Linux - Newbie 5 04-14-2003 12:19 PM


All times are GMT -5. The time now is 10:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration