LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
 
LinkBack Search this Thread
Old 10-29-2010, 04:46 PM   #1
coffee arabia
LQ Newbie
 
Registered: Oct 2010
Posts: 4

Rep: Reputation: 0
Lightbulb sort command


Hi,

I want to sort a file contains

9 1
9 2
10 1
10 2

to the order of

10 1
9 1
10 2
9 2

That is, the 2nd column is in incremental order, but for lines with the same 2nd column number, they are sorted in a reversed order.

I tried
Sort –k2 –k1 –n –r
But got everything in reversed order

10 2
9 2
10 1
9 1

Is there any simple way that works? Right now, I have to write a script to process this.

Thanks,
 
Old 10-29-2010, 04:57 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,627
Blog Entries: 10

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
Sure is

sort -k2,2n -k1,1nr
 
Old 10-29-2010, 05:01 PM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: OpenSUSE 12.1 CentOS 6.2
Posts: 9,010

Rep: Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352
Code:
sort -k2n -k1nr file
Edit: ops... too late!
 
Old 10-29-2010, 05:10 PM   #4
coffee arabia
LQ Newbie
 
Registered: Oct 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Great, thanks for both of you!!!
 
  


Reply

Tags
commands, linux users


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sort command help anu_1 Linux - Newbie 4 01-29-2010 04:34 AM
Sort command djfog Linux - Newbie 17 07-03-2008 03:05 AM
Sort command arya6000 Linux - Newbie 2 11-27-2007 07:50 PM
Sort Command saravanan1979 Programming 1 10-03-2004 11:36 AM
Using the Sort command in vi timnphx Programming 2 04-06-2001 11:39 PM


All times are GMT -5. The time now is 04:19 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration