- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- sorting column
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
тАО09-12-2005 05:17 PM
тАО09-12-2005 05:17 PM
I want to sort out column1 or column2 in ascending or descending order in the below output. This outputs are stored in a text file.
9.812 10023870 modifyUser managed2
7.741 7801930 modifyUser managed1
8.651 8900602 modifyUser managed2
11.94 12690787 login managed4
7.021 7127708 modifyUser managed4
6.009 6237126 migrateUser managed2
Can someone suggest combination of commands using grep, awk etc.
Thanks,
Shiv
Solved! Go to Solution.
- Tags:
- Sort
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 05:29 PM
тАО09-12-2005 05:29 PM
Solutionfor sorting string-value wise, i.e., 11.94 is smaller than 6.00, the first character is what is important for sorting
for column 1
sort -k 1 myfile > mysortedfile_col1
for column 2
sort -k 2 myfile > mysortedfile_col2
to sort for the numeric value:
sort -n -k 1 myfile > mysortedfile # sort acc to col 1 by numeric value
to reverse the sorting order
sort -rn -k 1 myfile > mysortedfile # sort acc to col 1 by numeric value in revrse order
hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 05:30 PM
тАО09-12-2005 05:30 PM
Re: sorting column
Assuming your data in file xyz.
Just do
# sort -k 2 < xyz|sort -k 1
11.94 12690787 login managed4
6.009 6237126 migrateUser managed2
7.021 7127708 modifyUser managed4
7.741 7801930 modifyUser managed1
8.651 8900602 modifyUser managed2
9.812 10023870 modifyUser managed2
If you want to sort in descending change the key option.
Regards,
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 08:11 PM
тАО09-12-2005 08:11 PM
Re: sorting column
sort -r
Plus if you want unique options there is the -u tag.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 11:16 PM
тАО09-12-2005 11:16 PM
Re: sorting column
# cat myfile | sort -k 2 > myfile2
# cat myfile2
will sort for column 2 , with follwoing output :
.812 10023870 modifyUser managed2
11.94 12690787 login managed4
6.009 6237126 migrateUser managed2
7.021 7127708 modifyUser managed4
7.741 7801930 modifyUser managed1
8.651 8900602 modifyUser managed2
$
---------------------------------------
Cheers,
Raj,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2005 12:02 AM
тАО09-14-2005 12:02 AM
Re: sorting column
sort -k 2 |sort -k 1 -r -o