If you want to print number of logged in users with their number of sessions. You can print using command line.
Shell script can give you more Robust results considering all test cases.
But this is a simple use of command line to print desired results.
You want to print number of users with their number of sessions.
$ who | cut -d " " -f1 | sort -n | uniq -c
who command prints number of logged in users
using cut command I have printed first column that is list of usernames
using sort I have sorted the list alphabatically.
using uniq, I have printed 'Group BY' of all users
now you want to know the number of instances ,you can use use uniq -c
Now output looks like: