LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-09-2012, 02:07 PM   #1
sal_x_sal
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Rep: Reputation: Disabled
sorting rows/lines in multiple level


Hi,

I am trying to sort a text file that has three columns on all the columns (first and two columns in ascending order and the third column with numbers in descensing order - smallest number first)

For example, the input file:

one a 12
two a -15
two a -8
three b 5
four b 2
four c -3
four c -8


should be outputted as:

four b 2
four c -8
four c -3
one a 12
three b 5
two a -15
two a -8

I tried to search online but I couldnt get this to work. This is the last thing I tried:
sort -k1,1 -k2,2 -nrk3, 3 in.txt > out.txt

Any help will be greatly appreciated!

Thanks.
 
Old 01-09-2012, 02:19 PM   #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,

Try this:
Code:
sort -k1,1 -k2,2 -k3,3n in.txt > out.txt
Hope this helps.
 
1 members found this post helpful.
Old 01-09-2012, 02:55 PM   #3
sal_x_sal
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
That worked perfectly!!
Thank you!
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] CAT command | multiple lines to multiple lines udiubu Programming 11 10-28-2011 06:09 AM
[SOLVED] Transpose multiple rows into a single column wonjusup Linux - Newbie 13 04-09-2011 06:53 AM
[SOLVED] Devilspie and Compiz Viewports on Multiple Rows Berrex Linux - Software 2 02-08-2011 02:16 AM
Sorting Rows of a file iframe Linux - Software 16 05-28-2009 04:38 AM
gnome-terminal how-to set lines/rows? longtex Linux - Software 3 10-21-2005 03:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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