Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort different way in different field...

Status
Not open for further replies.

h3nd

Programmer
Jul 1, 2006
147
AU
Hi guys,

I would like to have normal sort in field 1 and then sort reverse in field 2, how do I do that?

Here's the file
Code:
hr_rdb_bond_bill_futs_vol       Standard        850596
hr_rdb_capfloorvol      Standard        331766
hr_rdb_comcurves        Standard        6440227
hr_rdb_bond_bill_futs_vol       20060731        847667
hr_rdb_capfloorvol      20060731        330287
hr_rdb_comcurves        20060731        6434465

and I expect the result like this :
Code:
hr_rdb_bond_bill_futs_vol       Standard        850596
hr_rdb_bond_bill_futs_vol       20060731        847667
hr_rdb_capfloorvol      Standard        331766
hr_rdb_capfloorvol      20060731        330287
hr_rdb_comcurves        Standard        6440227
hr_rdb_comcurves        20060731        6434465

Thanks guys,
 
You can put sort specifiers for specific fields after the field definition, e.g.

[tt]sort -k 1,1 -k 2,2r -k 3,3n[/tt]

That would sort by field 1, then by field 2 reversed, then numerically by field 3, for example. Obviously you don't need the third parameter for your requirements.

Annihilannic.
 
A useful command:
man sort

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top