[Solved] Using w; how to list find all the users

Hi,

On my system, I have about 75 users. Some uers have two or three sessions on the same systems. when I do w, it shows all the sessions. Is there any way to find only the users and not worry about how many sessions. For example: you can see sshe has four connection. I only want to know the users. From the results below, I am looking for
sak, apr, sshe, xzha, peter. I tried doing w |grep -v but not working.

w |more
 16:06:52 up 568 days, 21:26, 75 users,  load average: 0.07, 0.10, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
sak pts/1    :37.0            21Feb12 263days  0.18s  0.18s -csh
apr pts/3    -                Tue18    4days  0.07s  0.07s -bin/tcsh
sshe  pts/4    -                18Oct12 25days  0.00s  7:34  kdeinit: kded 
xzha   pts/6    -                Fri17    0.00s  0.69s  0.58s -bin/tcsh
xzha   pts/7    -                Wed10    5days  0.00s 10.63s kdeinit: kded 
peter    pts/9    :24.0            13:45    2:20m 52.80s  0.09s -csh
sshe  pts/12   -                19Oct12 24days  0.15s  0.03s -bin/tcsh
sshe  pts/13   -                19Oct12 24days  0.00s  7:39  kdeinit: kded 
sshe  pts/15   -                19Oct12 24da
w | awk '!/PCPU/ && !/days/ { print $1 } ' | sort -u

awesome... bipinajith. awk works great.

That's not a reliable approach. If all of a user's sessions have been idle for a while, they will not be listed because !/days/ would exclude them all. The same condition will also exclude any sessions currently running a command line which includes "days". Any username in which the string "days" appears is also similarly doomed.

Similar issues apply to the use of !/PCPU/ .

In my opinion, a much more robust solution would specifically exclude the header:

w | awk 'NR>2 {print $1} | sort -u

Regards,
Alister

If you don't care about sorting :

w | awk 'NR>2&&!a[$1]++{print $1}'

or

w | awk '{NF=1}NR>2&&!a[$1]++'

List of unique users:

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