Solved

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

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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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…
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.
Suggested Courses

626 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