- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Sort by a column
Operating System - HP-UX
1753448
Members
4708
Online
108794
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО03-13-2008 06:39 PM
тАО03-13-2008 06:39 PM
I have a file like below , there are three columns , I want to sort it by dept , can advise what can i do ?
user username dept
===== ======== ====
user1 username1 dept1
user2 username2 dept4
user3 username3 dept2
user4 username4 dept3
user5 username5 dept1
user6 username6 dept3
user7 username7 dept2
user8 username8 dept4
user9 username9 dept2
user10 username10 dept1
The result that I want :
dept1
user username
===== ========
user1 username1
user5 username5
user10 username10
dept2
user username
===== ========
user3 username3
user7 username7
user9 username9
dept3
user username
===== ========
user4 username4
user6 username6
dept4
user username
===== ========
user2 username2
user8 username8
user username dept
===== ======== ====
user1 username1 dept1
user2 username2 dept4
user3 username3 dept2
user4 username4 dept3
user5 username5 dept1
user6 username6 dept3
user7 username7 dept2
user8 username8 dept4
user9 username9 dept2
user10 username10 dept1
The result that I want :
dept1
user username
===== ========
user1 username1
user5 username5
user10 username10
dept2
user username
===== ========
user3 username3
user7 username7
user9 username9
dept3
user username
===== ========
user4 username4
user6 username6
dept4
user username
===== ========
user2 username2
user8 username8
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2008 07:12 PM
тАО03-13-2008 07:12 PM
Re: Sort by a column
You need to pass it through sort:
$ sort -k3,3 file
If you want all that fancy formating, you need to write yourself a COBOL program. ;-)
tail +3 file | sort -k3,3 | awk '
BEGIN {last = "" }
{
if ($3 != last) {
if (NR != 1) print ""
print $3
print "user username"
print "===== ========"
last = $3
}
print $1, $2
}'
Note: since sort is sorting by strings, you get this order:
user1 username1
user10 username10
user5 username5
$ sort -k3,3 file
If you want all that fancy formating, you need to write yourself a COBOL program. ;-)
tail +3 file | sort -k3,3 | awk '
BEGIN {last = "" }
{
if ($3 != last) {
if (NR != 1) print ""
print $3
print "user username"
print "===== ========"
last = $3
}
print $1, $2
}'
Note: since sort is sorting by strings, you get this order:
user1 username1
user10 username10
user5 username5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-15-2008 01:20 AM
тАО03-15-2008 01:20 AM
Solution
Hi,
like Dennis' said: first sort, then format.
When sorting, include the first column as well, to get the usernames of each depX in alphabetical order:
sort -k 3,3 -k 1,1
mfG Peter
like Dennis' said: first sort, then format.
When sorting, include the first column as well, to get the usernames of each depX in alphabetical order:
sort -k 3,3 -k 1,1
mfG Peter
The Universe is a pretty big place,
it's bigger than anything anyone has ever dreamed of before.
So if it's just us, seems like an awful waste of space, right?
Jodie Foster in "Contact"
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP