- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: finding out unique values from a file??
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
03-24-2008 01:45 AM
03-24-2008 01:45 AM
consider a file contains values simply like this:
a=1
a=2
a=5
a=1
a=1
a=1
a=10
a=5
....
....
....
how to find out only unique values from this file?
for example, for the above file
a=1
a=2
a=5
a=10 is what i mean by unique values.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2008 01:48 AM
03-24-2008 01:48 AM
Re: finding out unique values from a file??
If there are only particular fields you want to check, you can use the sort -k option to define the fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2008 02:59 AM
03-24-2008 02:59 AM
Re: finding out unique values from a file??
thanks..
i was thinking i have to use a difficult "find and grep" a string..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2008 03:21 AM
03-24-2008 03:21 AM
Re: finding out unique values from a file??
cat file|uniq>new_file
New_file is ur unique file.
BR,
Kapil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2008 05:08 AM
03-24-2008 05:08 AM
Solutionassociative arrays in perl or awk, can also be very useful for these kind of tasks, notably if small transformations need to be done on the data before comparing, or when for example the number or occurances need to be counted.
For example in awk...
$ awk 'END {for (line in x){print line}} {x[$0]++}' x
For example in perl...
$ perl -ne '$x{$_}++ }{ foreach (sort keys %x) {print}'
So for both we take each line and increment (+create) an x array element for each.
At end report all key values.
With count:
$ perl -ne '$x{$_}++ }{ foreach (sort keys %x) {print qq($x{$_}; $_)}' x
4; a=1
1; a=10
1; a=2
2; a=5
Sorted by value:
perl -ne '$x{$_}++ }{ foreach (sort {(split(/=/,$a))[1] <=> (split(/=/,$b))[1]} keys %x) {print}' x
Enjoy!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2008 01:50 AM
03-25-2008 01:50 AM
Re: finding out unique values from a file??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2008 04:18 AM
03-25-2008 04:18 AM
Re: finding out unique values from a file??
cat myfile | sort | uniq -c | sort -n | more
This will give you a count of the uniq stuff and put the single entries on top. You could use it to find a misspelled werd....wort.... I mean word.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2008 04:30 AM
03-25-2008 04:30 AM
Re: finding out unique values from a file??
You reduce the number of processes you spawn by avoiding 'cat' to simply read a file!
Standard Unix commands read their input from a pipe or from a file(or files) specified on the commandline.
Thus:
# cat filename|sort
...wastes a process ('cat') to open and read a file simply to allow 'sort' to receive input. Instead:
# sort filename
...saves a process.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2008 04:33 AM
03-25-2008 04:33 AM
Re: finding out unique values from a file??
I seem to get more knowledge than I can dish out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2008 05:57 AM
03-25-2008 05:57 AM
Re: finding out unique values from a file??
That would be why I keep trying to help some, and surely it is the same reason for many others. In this particalur topic I was reminded of the -c option in uniq which.
We should frame Steve's reply in some "intro to forums document", along the line of, or incorporated in:
/66.34.90.71/ITRCForumsEtiquette/
Cheers,
Hein.