Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 22 Oct 2014, 22:00
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
script to sort pkg names [SOLVED]
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
sc0ttman


Joined: 16 Sep 2009
Posts: 2385
Location: UK

PostPosted: Thu 07 Feb 2013, 14:59    Post subject:  script to sort pkg names [SOLVED]
Subject description: how to list newest version first?
 

I have a problem, and no solution, as yet.

I want to re-order a list, so that the pkgs are listed in alphabetical order, except that I want the newest version first.

If I use `sort|uniq` I get an alphabetical order, but oldest version first.
If I use `sort -r|uniq` I get an reverse alphabetical order, but newest version first.

How do I get normal alphabetical order, and newest version first?

Code:
# echo "$VAR" | sort
freeciv-1.99
freeciv-2.1
freeciv-2.2
freeciv-3.1
mplayer-1.2.3
mplayer-2.3.4
# echo "$VAR" | sort -r
mplayer-2.3.4
mplayer-1.2.3
freeciv-3.1
freeciv-2.2
freeciv-2.1
freeciv-1.99


EDIT: SOLVED!

This solves it (modified from 3rd post.. added quotes to $VAR.. necessary?):

Code:
echo "$VAR" | sort --field-separator='-' -k1,1d -k2gr

_________________
Akita Linux, VLC-GTK, Pup Search, Pup File Search

Last edited by sc0ttman on Sun 24 Feb 2013, 06:41; edited 2 times in total
Back to top
View user's profile Send private message 
GustavoYz


Joined: 07 Jul 2010
Posts: 897
Location: .ar

PostPosted: Thu 07 Feb 2013, 15:22    Post subject:  

Deleted...
_________________


Last edited by GustavoYz on Thu 07 Feb 2013, 15:59; edited 2 times in total
Back to top
View user's profile Send private message 
GustavoYz


Joined: 07 Jul 2010
Posts: 897
Location: .ar

PostPosted: Thu 07 Feb 2013, 15:50    Post subject:  

Just realize that will fail anyway. Embarassed
More like this one:
Code:
echo $VAR | sort --field-separator='-' -k1,1d -k2gr

Razz

_________________

Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5037
Location: Arizona, U.S.A.

PostPosted: Fri 08 Feb 2013, 03:37    Post subject:  

Hi sc0ttman; Did you try -n for numeric sort?
You`ll need to put it in a loop to isolate the package names and then sort each of them numerically.
It works in my tests.
Back to top
View user's profile Send private message 
sc0ttman


Joined: 16 Sep 2009
Posts: 2385
Location: UK

PostPosted: Fri 08 Feb 2013, 20:30    Post subject:  

Hi guys..

sunburnt, I know *nothing* about 'sort' and so had tried nowt when posting... I then saw the replies and went and did some experiments... Only using -n, without the -k1 -k2 stuff, worked when stripping out the names entirely, but mixing it all back up again looked daunting!

Again, I know nothing about this, so I might have it wrong.

GustavoYz, that works well, not perfect, but good enough! As far as I can tell, any version numbers that are immediately followed by letters, rather than a dash or underscore etc, do not go where I want, but that's fine... I can live with that.

_________________
Akita Linux, VLC-GTK, Pup Search, Pup File Search
Back to top
View user's profile Send private message 
GustavoYz


Joined: 07 Jul 2010
Posts: 897
Location: .ar

PostPosted: Fri 08 Feb 2013, 21:15    Post subject:  

The thing is that it requires two tipes of sorting, in hierarchical order: alphabetical and then numeric.
Quote:
[..]As far as I can tell, any version numbers that are immediately followed by letters, rather than a dash or underscore etc, do not go where I want[...]

Yes, if no field separator that could work as a pattern on each filename, it wont work.
I think there is no way if wont split the name in fields somewhere and somehow if it has to be by just using sort, as far as I know.
Hope it works. Razz

_________________

Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0494s ][ Queries: 11 (0.0034s) ][ GZIP on ]