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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix Sort (two fields) 1

Status
Not open for further replies.

mwesticle

Programmer
Nov 19, 2003
51
US
Hi...
I need to sort a pipe-delimited file that has three numeric fields. I need to group by the first field (ascending), and group by the third field (descending). The second field is irrelevant. So, basically, I need a file that looks like this:

166|29114 |327.97
166|29127 |44.35
166|82828 |500.00
112|27272 |36.00
112|01010 |55.12

To look like this:

112|01010 |55.12
112|27272 |36.00
166|82828 |500.00
166|29114 |327.97
166|29127 |44.35

Anyone out there know what I'm sayin'? Any help would be much appreciated. Thanks a million!!!
 
This will work from the command line, so if you need
to have it occur in a script place the following command where you need it to go.


sort -t'|' +0n -1 +2nr -3 <datafile name>


The breakdown of what is happening.

sort -t'|' # Set the pipe to be the field separator

+0n -1 # Sorts the first field numerical (Sort is zero based)

+2nr -3 # Sorts field 3 in reverse numeric order


Hope this helps,


Steve


 
Perfect! That works beautifully. Thank you very much!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top