Venkata Venkata - 2 months ago 10
Linux Question

How to write an awk script to list users currently using the system along with a count of the number of times they have logged in?

I pretty new on Unix and just started exploring awk. I am aware, using "who", we can get the list of users, and "wc" to get the count, but not sure how to write them in a script file and then run that from prompt.I have basic idea of the format, awk -f scriptname.awk filename to run from a file. Please guide me through this.


Try the following:

who | awk '{w[$1]++} END { for (x in w) { print x,"has "w[x]"active sessions" }}'