How to exclude repetitions of words in the shell output?
Hi,
I have a line with N words as a shell output. How I can exclude those words that appear more than once? This is what I do. I need to print the list of current users on the system. # who -q | grep -v '#' Gives me the string of users: mike mike john mike john mike mike mike The usernames are repeating (each user logged in several times), which I don’t need. I need just this: mike john How I can exclude all the repetitions in the output? grep, sed, awk? Thanks!!! |
this works, but maybe there is a easier way about this.
Code:
#!/bin/bash |
who|awk '{print $1}'|sort -u
|
Code:
who -u | cut -d' ' -f1 | sort | uniq |
Code:
who -q | grep -v '#' | tr " " "\n"| sort -u |
Quote:
|
A little off topic but... don't forget
Code:
who mom likes |
Alternately
who|awk '{print $1}'|uniq |
Another way:
Code:
who | awk '{array[$1]} END{for (i in array) print i}' |
Quote:
|
Quote:
These funnies were always great. The two variants below and their (usually) identical output often befuddled new users: $ who am i? mrc ttyp0 Jul 25 20:23 (mrc.example.com) $ who am i mrc ttyp0 Jul 25 20:23 (mrc.example.com) And of the omniscience of csh: % Got a light? Got: No match. Ah, those were the days... :-) |
Quote:
# make love Make: Don’t know how to make love. Stop. ;) |
All times are GMT -5. The time now is 06:03 AM. |