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
  Search this Thread
Old 10-29-2010, 05: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, 05:57 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Sure is

sort -k2,2n -k1,1nr
 
Old 10-29-2010, 06:01 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Code:
sort -k2n -k1nr file
Edit: ops... too late!
 
Old 10-29-2010, 06: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



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

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

All times are GMT -5. The time now is 02:30 AM.

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