- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: List and count routine
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
тАО10-22-2009 10:57 PM
тАО10-22-2009 10:57 PM
List and count routine
I am looking for a routine to list the number of user claims per code.
For example, jones accesses to 2 codes A001 (twice) and A123 (once).
The desired output for the given input is displayed below:
input:
jones:A001
jones:A001
peters:A001
Peters:T909
nichols:A001
jones:A123
desired output:
jones (2) A001
jones (1) A123
peters (1) A001
peters (1) T909
nichols (1) A001
An awk solution would be helpful. Thanks
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-22-2009 11:21 PM
тАО10-22-2009 11:21 PM
Re: List and count routine
These are all boolean AND conditions and many to many relationships. I don't think a shell script is suitable and I'm not good enough to answer in PERL. Wait a bit for JRF or another PERL guru's input on this.
In short, I could do but it'd be long and their are 3rd and 4th generation programming languages more suitable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2009 12:07 AM
тАО10-23-2009 12:07 AM
Re: List and count routine
# uniq -c filename.txt
2 jones:A001
1 peters:A001
1 Peters:T909
1 nichols:A001
1 jones:A123
This can then be chopped up:
# uniq -c oop23i4p |replace ":" " "| awk {'print $2 " (" $1 ") " $3}'
jones (2) A001
peters (1) A001
Peters (1) T909
nichols (1) A001
jones (1) A123
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2009 12:09 AM
тАО10-23-2009 12:09 AM
Re: List and count routine
don't assign me any points for this specific post
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2009 02:24 AM
тАО10-23-2009 02:24 AM
Re: List and count routine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2009 04:10 AM
тАО10-23-2009 04:10 AM
Re: List and count routine
In Perl:
# perl -nle '$object{$_}++;END{for $key (sort keys %object) {@a=split /:/,$key;print $a[0]," (",$object{$key},") ",$a[1]}}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2009 04:34 AM
тАО10-23-2009 04:34 AM
Re: List and count routine
You already got several excellent methods.
Here is another one in Perl.
#!/usr/bin/perl
use strict;
my @unique = ();
my @unique2 = ();
my %seen = ();
my @MyArr = ();
my @arr = ();
my $mycount = 0;
my %myhash;
while () {
chomp $_;
push(@MyArr, lc($_));
}
foreach my $elem (@MyArr)
{
$seen{$elem}++;
# my $result = sprintf("%-10s %s %5s\n", $arr[0], $arr[1], "($seen{$elem})");
$myhash{$elem} = "($seen{$elem})";
}
foreach my $hkey (keys %myhash) {
my @arr = split(/:/, $hkey);
my $result = sprintf("%-10s %5s %s\n", $arr[0], $myhash{$hkey}, $arr[1]);
# print "$hkey...$myhash{$hkey}\n";
print "$result";
}
exit(0);
__DATA__
jones:A001
jones:A001
peters:A001
Peters:T909
nichols:A001
jones:A123
When you run it, it formats the results as:
peters (1) a001
jones (2) a001
jones (1) a123
nichols (1) a001
peters (1) t909
Cheers,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2009 04:45 AM
тАО10-23-2009 04:45 AM
Re: List and count routine
By the way, using my Perl solution means that the username "peters" differs from "Peters", Hence using your exact input will produce this output:
Peters (1) T909
jones (2) A001
jones (1) A123
nichols (1) A001
peters (1) A001
My script produces sorted output, too. Had you had "peters:A001" and "Peters:A001" these too would have been treated as discrete keys.
Regards!
...JRF...