Shell script output Sort and count number of occurrence of lines

iKnow-IT banner

If you have a command that you will count the unique occurrences in lines.
e.q. you have a command that shows a system list and a version number 
and you are interested in how many of each version in this list

$ tacmd listsystems

host1:08               08  Y
host2:08               08  Y
host3:08               08  Y
host4:08               08  Y
host5:08               08  Y
host6:08               08  Y

You can sort and count the number of occurrence of the lines 

$ tacmd listsystems | awk '{print $3}' | sort | uniq -c


the command

$ tacmd listsystems | awk '{print $3}'

gives the result

The trick is 

 <command> | sort | uniq -c

sort the order and then count the unique values