LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 06-22-2007, 11:05 AM   #1
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 208Reputation: 208Reputation: 208
command to sort by floats in fourth column of standard output


I have a command that prodcues a list of servers...

Code:
anvil                ia64linux      4  4.19    63.2G    26.7G   136.7G     1.0M
carbon               ia64linux      4  0.03    15.2G     1.3G     2.4G      0.0
cesium               ia64linux      4  3.99     9.9G     1.0G     5.0G      0.0
delaware             aix43          4  0.03    16.0G     1.3G    22.4G     4.1M
flame                lx24-amd64     8  8.62     3.9G     3.3G    16.0G     1.5G
...
The fourth column is the cpu load. I would like to sort the output by the load. Is there anyway to pipe this output and then sort it by the number in the fourth column??

Thanks!
Jameson
 
Old 06-22-2007, 11:25 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

The sort command should be able to do just that:
Code:
$ sort -k 3 testfile
delaware             aix43          4  0.03    16.0G     1.3G    22.4G     4.1M
carbon               ia64linux      4  0.03    15.2G     1.3G     2.4G      0.0
cesium               ia64linux      4  3.99     9.9G     1.0G     5.0G      0.0
anvil                ia64linux      4  4.19    63.2G    26.7G   136.7G     1.0M
flame                lx24-amd64     8  8.62     3.9G     3.3G    16.0G     1.5G
Take a look at the -k option in the sort manpage.

Hope this helps.
 
Old 06-22-2007, 12:31 PM   #3
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Original Poster
Rep: Reputation: 208Reputation: 208Reputation: 208
sort output by float, not string?

Very good! Thanks so much. One issue:

Lines with loads > 9.99, i.e. 10.00+ (two digit integral loads) are sorted in the middle of one digit integral loads.

That is to say..
Code:
host1 1.23
host2 13.00
host3 2.57
etc...

Perhaps there is a way to read these values as floats, not as string?

Thanks!
 
Old 06-22-2007, 12:54 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Try this instead: sort -k4g infile (btw: the sort column is 4, not 3 as in my previous post).

Hope this helps.
 
Old 06-22-2007, 02:27 PM   #5
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Original Poster
Rep: Reputation: 208Reputation: 208Reputation: 208
There it is! Thanks for your help.
 
  


Reply

Tags
float, hosts, load, server, sort


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
Can't get "sort' to work on a particular column smkamene Programming 11 06-30-2006 11:37 AM
can't capture 'at' command standard output to a file bartoni Linux - General 3 02-28-2006 04:52 PM
'sort' fn. in C++ standard library frankie_DJ Programming 2 12-14-2004 03:27 PM
How to redirect standard output of piped command to log file andrewstr Linux - General 10 02-04-2004 03:07 PM
Sorting of multi-column output rytrom Linux - Newbie 11 09-15-2003 12:31 PM


All times are GMT -5. The time now is 01:55 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration