LinuxQuestions.org
Review your favorite Linux distribution.
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 07-01-2015, 12:29 AM   #1
DNG
LQ Newbie
 
Registered: Jul 2015
Posts: 6

Rep: Reputation: Disabled
Sorting file data in descending order


Hi all, I am new to Linux and im having a hard time figuring out the SORT command.
I have a file with the sample data below.How d o i display the contents of the file sorted according to the marks in descending order

Student Name Code Marks
s0001 raja semp 78
s0005 usha semr 96
s0010 skp sema 85
s0011 john semb 60
s0008 mike seml 67
 
Old 07-01-2015, 12:54 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,385

Rep: Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045
That header line will make things awkward - show us what you've tried.
 
Old 07-01-2015, 01:02 AM   #3
DNG
LQ Newbie
 
Registered: Jul 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
input : cat studentfile.txt | sort -k4rn
output: s0005 usha semr 96
s0010 skp sema 85
s0001 raja semp 78
s0008 mike seml 67
s0011 john semb 60
Student Name Code Marks
 
Old 07-01-2015, 01:49 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,385

Rep: Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045Reputation: 3045
So you've got the idea of keys ok.
Linux has the "head" and "tail" commands in addition to "cat" - if you don't care about the header, "tail -n +2" in place of "cat" will work. It is possible to retain the header as well, but not with sort alone AFAIK.
 
  


Reply


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
File manager sorting by name puts files in the wrong order? listless Linux - Desktop 2 06-05-2014 05:47 PM
Ascending or descending order for poll results? linuxlover.chaitanya LQ Suggestions & Feedback 3 02-10-2011 12:24 AM
[SOLVED] Sort in descending order according to a column of an array flea89 Linux - Newbie 3 03-14-2010 07:00 PM
how to list folder size in descending order ? Winanjaya Linux - Server 2 02-09-2010 01:32 AM
Sorting data in output file lluciano Linux - General 2 08-19-2005 11:37 AM

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

All times are GMT -5. The time now is 01:50 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