18

With help of the who command we can get active users, I want only the first field such as

user 1
user 2
user 3

1 Answer 1

27

You can get just the user names like so:

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

Where who lists all logged in users, passes the output to awk which only prints the first section ("column") of text for every line, passes it to sort which sorts the output.

5
  • 6
    Or use sort -u instead of sort | uniq
    – DK Bose
    Feb 26, 2014 at 11:00
  • Ok, did not know about that option. (Or knew and forgot!)
    – Stabledog
    Feb 26, 2014 at 12:52
  • 2
    You don't need to use awk: who | cut --delimiter=' ' --field=1 | sort --unique (the short version reads: who|cut -d' ' -f1|sort -u). Mar 4, 2014 at 22:49
  • 1
    Unix always provides so many ways to skin a cat. Its amazing any cats still have fur.
    – Stabledog
    Mar 5, 2014 at 2:56
  • @PaddyLandau Why not put your answer in its own answer?
    – AmanicA
    Mar 6, 2014 at 23:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .