- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sort with -u unique option
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
Forums
Discussions
Discussions
Discussions
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
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
07-25-2006 09:41 AM
07-25-2006 09:41 AM
cat $secdir/*.passwd | awk -F: '{print $1,$3,$4,$5}'
Here is an example of the raw data for one logonid:
cat $secdir/*.passwd | awk -F: '{print $1,$3,$4,$5}' | sort|grep best1
best1 1100 1100 best1
best1 1100 1100 best1
best1 1100 1100 best1
best1 1100 1100 best1
best1 1100 1100 best1
best1 1100 1100 best1
best1 1500 550 Application ID,PDC,,
best1 1500 550 Best1,,,
When I run the following command:
cat $secdir/*.passwd | awk -F: '{print $1,$3,$4,$5}' | sort -u -k1
I would expect to get only one line back (if I understand the -u option correctly from the man page). But instead I get:
best1 1100 1100 best1
best1 1500 550 Application ID,PDC,,
best1 1500 550 Best1,,,
It's as if the -u was being applied to the entire line, rather than just the first key field.
Here is the section of the man page for sort I am relying on:
-u Unique: suppress all but one in each set of lines
having equal keys.
Any ideas?
Scott
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2006 09:46 AM
07-25-2006 09:46 AM
Re: sort with -u unique option
Why not just do:
cat $secdir/*.passwd | awk -F: '{print $1}' | sort -u
I don't really see what you are gaining, or trying for, by including the other information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2006 09:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2006 09:49 AM
07-25-2006 09:49 AM
Re: sort with -u unique option
I need the other four fields (UID, GID, etc) for the report that is eventually generated, but only one line per logonid.
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2006 09:53 AM
07-25-2006 09:53 AM
Re: sort with -u unique option
sort -k1,1 was all that was needed!
I 'assumed' wrong that 'sort -k1' only sorted on the first key. In reality (from the sort man page):
"A missing field_end means the end of the line."
Thanks!
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2006 09:53 AM
07-25-2006 09:53 AM
Re: sort with -u unique option
Yes, your specification for the sort key is actually until the end-of-line.
This is a common mistake. You need to specify both the start and the end of the key:
# sort -u -k1,1
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2006 09:54 AM
07-25-2006 09:54 AM