RE: group by & count command?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Not being particularly resourceful with bourne or bash scripting,
my answer would be that this would be easiest with perl using a
hash.

something like:

my %count;
open( IN, "< yourfile" );
while( <IN> ) {
    $count{$_}++;
}
close( IN );

foreach my $key( sort keys %count ) {
    print "$key - $count{$key}\n";
}

-Steve

> -----Original Message-----
> From: redhat-list-admin@xxxxxxxxxx
> [mailto:redhat-list-admin@xxxxxxxxxx]On Behalf Of Mike Vanecek
> Sent: Tuesday, November 25, 2003 1:01 PM
> To: redhat_list
> Subject: group by & count command?
> 
> 
> I have a bash command that is essentially grep | sed | sort. 
> It creates a file
> of sorted records. What I would like to do next is create a 
> report that lists
> each unique item and its count.
> 
> 1
> 1
> 1
> 2
> 3
> 3
> 
> would be
> 1 - 3
> 2 - 1 
> 3 - 2
> 
> Can this be done via a bash command and if yes, how? 
> Otherwise, I would assume
> it needs to be fed to a perl script?
> 
> Thanks.
> 
> 
> -- 
> redhat-list mailing list
> unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
> https://www.redhat.com/mailman/listinfo/redhat-list
> 
> 


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux