pradeep reddy wrote:
Hi,

Hello,

I have a script which greps for a word in a file contains records.
I grabbed a particular column & sent the colomn values to a file.
I need to find each column value, the times it appeared in the file.
My script is: grep sceneority <file> | cut -f 6 >> swi
I am stuck at how to find the occurance of column values in "swi" file.
Plz help me.
Ex:
The file has following column values: 123
324
123
123
435
435
The output should be 123 is 3 times
324 is 1 time
435 is 2 times

my $file = '<file>';

open my $FH, '<', $file or die "Cannot open '$file' $!";

my %counts;
while ( <$FH> ) {
    next unless /sceneority/;
    $counts{ ( split /\t/ )[ 5 ] }++;
    }

for my $key ( sort { $a <=> $b } keys %counts ) {
print "$key is $counts{$key} time", $counts{ $key } == 1 ? "\n" : "s\n";
    }




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to