Solved

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

Posted on 2008-10-21
2
925 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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 …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

776 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