LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 05-15-2011, 07:24 AM   #1
Poseidon
LQ Newbie
 
Registered: May 2011
Posts: 7

Rep: Reputation: 6
Using sort from coreutils


Hi All,

I'm sure this is pretty obvious but I obviously can't see the wood for the trees!

I have a text file (index.txt) such as this ->

csh 99
vi 155
csh 123
pipe 101
emacs 163
socket 415
pipe 23

and I want to sort it on the the first field alphabetically and then on the second field numerically. So I tried using

sort +0 -1 +1 -2n index.txt

I would have thought this would do it but the numbers are always in reverse order..like this

csh 123
csh 99
emacs 163
pipe 101
pipe 23
socket 415
vi 155

why on earth is it not coming out as (which is what I want)

csh 99
csh 123
emacs 163
pipe 23
pipe 101
socket 415
vi 155

Many thanks for any insight
James
 
Old 05-15-2011, 08:13 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Gives this a try:
Code:
sort -k1,1 -k2,2n index.txt
csh 99
csh 123
emacs 163
pipe 23
pipe 101
socket 415
vi 155
Hope this helps.
 
Old 05-15-2011, 08:41 AM   #3
Poseidon
LQ Newbie
 
Registered: May 2011
Posts: 7

Original Poster
Rep: Reputation: 6
Smile

Hey, that's great thank you very much.
I am working from some very old (20yrs) Unix notes and I guess the syntax is a different flavour.

Cheers
James
 
Old 05-15-2011, 08:46 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

You're welcome

BTW: Can you put up the [SOLVED] tag? (first post -> Thread Tools)
 
  


Reply



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
Is there a sort of 2nd SSH daemon server, sort of JAILKIT, in the debian repositories frenchn00b Debian 5 06-20-2010 04:03 AM
sort (GNU coreutils) 7.4 not sorting in ascii order (asked and answered). bartonski Linux - Software 1 03-07-2010 11:48 AM
How do I do filtering in Perl (keep sort order and sort again by another means)? RavenLX Programming 9 12-19-2008 10:12 AM
selection sort compiles but does not sort the array as desired ganesha Programming 2 04-20-2008 07:44 AM
Is there a line limit with the sort utility? Trying to sort 130 million lines of text gruffy Linux - General 4 08-10-2006 08:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:30 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
Open Source Consulting | Domain Registration