I want to get a list of the currently logged users and their respective IP addresses.
I tried the following command line:

w -s

However, the TTY, IDLE and WHAT columns are also displayed. I don't want those columns to be displayed as I plan to use only the needed information as an input to a script. Is there any way to filter those columns out? Any way of getting a list with just the users and their IPs?


Does this work for you?

w -hs|awk '{printf "%s\t%s\n",$1,$3}'
  • It does. Thank you very much! Wow, it seems that I definitely need to learn more about awk. I feel so embarrassed :P – PALEN Apr 8 '13 at 3:50
  • It's a pretty handy tool for minor data processing tasks, I highly recommend adding it to your repertoire. – tink Apr 8 '13 at 4:12

Your Answer

