I realize that you spoke about col5, but I had to use the data as you supplied it. If the flag is really in col5 (i.e. presumably field subscript 4), change the one-liner to:$ echo ' james yes dave yes mike yes ken no jon yes jon no ken yes jon yes mike no james yes dave yes mike no ken no jon yes jon yes ' | perl -nE 'my ($name, $val) = split; $hash{$name} ++ if $val eq "ye +s"; END{ say "$_\t$hash{$_}" for keys %hash}' james 2 mike 1 dave 2 jon 4 ken 1
perl -nE 'my ($name, $val) = (split)[0,4]; $hash{$name} ++ if $val eq +"yes"; END{ say "$_\t$hash{$_}" for keys %hash}'
In reply to Re: keep only unique elements in an array displaying number of duplicates.
by Laurent_R
in thread keep only unique elements in an array displaying number of duplicates.
by john.tm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |