cancel
Showing results for 
Search instead for 
Did you mean: 

unique value from list

 
syedar
Advisor

unique value from list

Hi All,

I have a list(T3.lst) which contains these values
TKTGRS8028
TKTGRS8028
TKTGRS8028
TKTGRS8028
TKTGRS8028
TKTGRS8263
TKTGRS8263
TKTGRS8263
TKTGRS8263
TKTGRS8263
TKTGRS8263
TKTGRS8263
TKTGRS8263
TKTGRS8263
TKTGRS8263
TKTGRS8263
TKTGRS8263
TKTGRS8439
I need to know how may times similar value exists.

5 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: unique value from list

Hi:

You could do:

# perl -nle '$x{$_}++;END{for $val (sort keys %x) {print join "=",$val,$x{$val}}}' file

...which using your data gives:

TKTGRS8028=5
TKTGRS8263=12
TKTGRS8439=1

Regards!

...JRF...
Mel Burslan
Honored Contributor

Re: unique value from list

In posix-shell or ksh, it would be a little more convoluted and not as elegant as JRF's perl solution but here it is:

for i in `cat T3.lst|sort|uniq`
do
ct=`grep "$i" T3.lst|wc -l`
echo "$i = $ct"
done

HTH
________________________________
UNIX because I majored in cryptology...
OldSchool
Honored Contributor

Re: unique value from list

a simple:

sort T3.lst | uniq -c

produces:
5 TKTGRS8028
12 TKTGRS8263
1 TKTGRS8439

which may (or may not) suffice for your needs.


Steven E. Protter
Exalted Contributor

Re: unique value from list

Shalom,

cat file | sort -u

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
OldSchool
Honored Contributor

Re: unique value from list

SEP: While that gives you unique entries, the last line of the original post requests counts of each (at least thats how I read it)