GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sort & uniq
Operating System - HP-UX
1845486
Members
2998
Online
110244
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
Forums
Discussions
Discussions
Discussions
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
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
12-09-2005 01:40 AM
12-09-2005 01:40 AM
sort & uniq
in a script I have the following:
while read fakeuser
do
grep $fakeuser passgvts >> queryusers
done < testnotokusers
However I have a lot of repeats in the file queryusers due to having two same entries in testnotokusers i.e. gillar and having two very similar entries in passgvts i.e. gillars & gillarst. Hence for each entry I end up with it being outputted to queryusers twice as it is being grepped twice i.e. the queryusers file may look like:
gillars
gillarst
gillars
gillarts
As there are hundreds of entries I can not go through the whole file deleting repetitions. It has been suggested that I do something like the following at the bottom of the script
cat queryusers ¦ sort ¦ uniq > newfile
hence this would sort the queryusers file and send unique entries to the newfile. Can someone please tell me what options I need for "sort" and "uniq" if any. Thanks
while read fakeuser
do
grep $fakeuser passgvts >> queryusers
done < testnotokusers
However I have a lot of repeats in the file queryusers due to having two same entries in testnotokusers i.e. gillar and having two very similar entries in passgvts i.e. gillars & gillarst. Hence for each entry I end up with it being outputted to queryusers twice as it is being grepped twice i.e. the queryusers file may look like:
gillars
gillarst
gillars
gillarts
As there are hundreds of entries I can not go through the whole file deleting repetitions. It has been suggested that I do something like the following at the bottom of the script
cat queryusers ¦ sort ¦ uniq > newfile
hence this would sort the queryusers file and send unique entries to the newfile. Can someone please tell me what options I need for "sort" and "uniq" if any. Thanks
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2005 01:51 AM
12-09-2005 01:51 AM
Re: sort & uniq
If the queryusers file has the name as the first entry on the line, then |sort|uniq will reduce all occurances of the same name to just one. If the problem is that you are looking for an exact word (ie, gillar) and do not want anything else (like gillars and gillarst), use the -w option in grep. This option is only available with the latest patch for grep.
Bill Hassell, sysadmin
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2005 06:21 AM
12-10-2005 06:21 AM
Re: sort & uniq
ah... a continuation/parallel thread to:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=980856
As bill says... you may want to grep explicitly for a word, or use an egrep anchoring your words at begin of line, following them with whitepace, or anything else to make it do what you want exactly.
Now if you do want to post-process that queryusers files, and not simply avoid the dups as per the other topic, then just can just tell uniq to look only for the first N characters:
sort queryusers | uniq -w 6
but then why not go one step further and jsut tell srot exatly what you want:
Something like:
sort -k 1.1,1.6 -u queryusers
caveat... I did not have access to an hpux box just now, so I only tested on my CD player which runs redhat linux 2.4
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2005 08:15 PM
12-11-2005 08:15 PM
Re: sort & uniq
Hi Ravinder,
sort -uo newfile queryusers
should be sufficent to remove dusplicates from queryusers if this file contains only the name of teh users otherwise is necessary to provide the key for the sort in teh format
-k to teh sort.
You can type man sort to look at this.
HTH,
Art
sort -uo newfile queryusers
should be sufficent to remove dusplicates from queryusers if this file contains only the name of teh users otherwise is necessary to provide the key for the sort in teh format
-k to teh sort.
You can type man sort to look at this.
HTH,
Art
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.
Company
Events and news
Customer resources
© Copyright 2026 Hewlett Packard Enterprise Development LP