Solved

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

Posted on 2008-10-21
2
929 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Utilizing an array to gracefully append to a list of EmailAddresses
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

710 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