- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Sort Problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2003 11:47 PM
тАО12-22-2003 11:47 PM
following command (Sorting on 2 and 3 rd columns only)
sort -t':' -k2,3 a.lst
cat a.lst
1:3:3:4
1:4:3:5
1:2:3:4
1:5:3:4
1:4:3:4
The output we are getting is
1:2:3:4
1:3:3:4
1:4:3:4
1:4:3:5
1:5:3:4
The output we are expecting is :
1:2:3:4
1:3:3:4
1:4:3:5
1:4:3:4
1:5:3:4
Can anyone suggest us a solution.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-22-2003 11:52 PM
тАО12-22-2003 11:52 PM
Re: Sort Problem
can you explain, why you want to sort column 4 in reverse order?
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-23-2003 12:04 AM
тАО12-23-2003 12:04 AM
Re: Sort Problem
our intention is to sort on cloumns 2 and 3 only. In the above example 1:4:3:5 preceeds
1:4:3:4, so we are expecting the same order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-23-2003 12:07 AM
тАО12-23-2003 12:07 AM
Re: Sort Problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-23-2003 12:13 AM
тАО12-23-2003 12:13 AM
SolutionI often use nl to play this kind of games ...
nl -s: a.lst | sort -b -t':' -k3,4n -k1,1n | cut -f2- -d:
In this case it add temporarily a new sort field to keep trace of the original order which is not garanted on non sorted fields.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-25-2003 02:36 AM
тАО12-25-2003 02:36 AM
Re: Sort Problem
The output you are getting is in sort-order for a sort on columns 2 and 3 -- you told the sort to not look at the columns after column 3, so for this sort, 1:4:3:4 and 1:4:3:5 are identical. The 1:4:3:5 preceeds in the output because it was encountered first in the input, and when the sort encountered an identical record (":4") you had defined no reason for it to change their order. To produce the output you desire, sort on columns 1 through 7 -- ie: the full length of the strings being sorted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-25-2003 04:33 AM
тАО12-25-2003 04:33 AM
Re: Sort Problem
Jean-Louis has the perfect answer. I was thinking to programme something like this, but seeing, that he was there before, I did not try to post a slightly different version. Take it, it works!!
greetings,
Michael