0

I am trying to figure out how to get a list of logged in users and then with pipes sorting this list and only show every unique occurence.

I am almost there but the problem is that the "who-command" doesnt seem to allow to list just the user by name - it lists others parameters such as logintime, threads and so on. That results in making every every line unique.

here is my command

who | sort | uniq

and the result:

eric     :3           2014-09-25 15:23 (:3)
karen    :0           2014-09-25 14:41 (:0)
karen    pts/0        2014-09-25 14:48 (:0)
john     :2           2014-09-25 15:23 (:2)
carol    :1           2014-09-25 15:22 (:1)
carol    pts/25       2014-09-25 15:22 (:1)
admin    :4           2014-09-25 15:23 (:4)

So - how do I get a list of only the unique names in a list?

java
  • 1,165
  • 1
  • 25
  • 50

2 Answers2

1

Take the first column only:

who | cut -d ' ' -f 1 | sort -u
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
1

I'd use:

who | awk '{print $1}' | sort | uniq

But there is more than one solution:

Community
  • 1
  • 1
Benjamin
  • 1,726
  • 1
  • 14
  • 35