Solved

in Bash's Sort, how do I sort by a second or third field ?

Posted on 2008-10-21
2
924 Views
Last Modified: 2013-12-27
On solaris I have data:  

N00412L3.daysold 140 37
N00160L3.daysold 18 38
N00158L3.daysold 11 39

the 14 days old of the tape and I want to sort to find tapes over 90.

I think sort with a -t or a -k may do it.  I think this is not written about much on the web :)


0
Comment
Question by:itguy411
2 Comments
 
LVL 20

Accepted Solution

by:
edster9999 earned 300 total points
ID: 22767668
sort -k 2
would sort the list based on the second field
this doesn't really work as it will be in this order :

N00158L3.daysold 11 39
N00412L3.daysold 140 37
N00160L3.daysold 18 38

as it is done by alphabet order so it is looking at 11, 14, 18

sort -k 2 -n
gets it sorted by numbers :

N00158L3.daysold 11 39
N00160L3.daysold 18 38
N00412L3.daysold 140 37

and finally
sort -k 2 -n -r
the -r gets it in reverse order

N00412L3.daysold 140 37
N00160L3.daysold 18 38
N00158L3.daysold 11 39

so now you can go down the list until you hit 90.
0
 

Author Closing Comment

by:itguy411
ID: 31508299
This really helps me

You rocke

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Fine Tune your automatic Updates for Ubuntu / Debian
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now