|
Prev: Opening a File via Pipes, Redirection and direct access and its effect on Command
Next: New shell service (Debian / non-profit)
From: robusto33 on 14 Apr 2008 19:08 Hi, I have a quick question about a script. I'm using the command "who" and "sort" to create a list of a sorted, logged-in users that belong to a certain group. Can anyone help me make a script that will show a list of ONLY the usernames of the logged in users? I've been trying for hours and can't get it to display what I want.
From: Maxwell Lol on 14 Apr 2008 23:23 robusto33(a)gmail.com writes: > Hi, I have a quick question about a script. I'm using the command > "who" and "sort" to create a list of a sorted, logged-in users that > belong to a certain group. Can anyone help me make a script that will > show a list of ONLY the usernames of the logged in users? I've been > trying for hours and can't get it to display what I want. a quick and dirsty version is who | awk '{print $1}' | sort|uniq This one uses 2 processes instead of 4: who | awk '!a[$1]++ {print $1}'
From: Dan Stromberg on 15 Apr 2008 14:25
On Mon, 14 Apr 2008 23:23:21 -0400, Maxwell Lol wrote: > robusto33(a)gmail.com writes: > >> Hi, I have a quick question about a script. I'm using the command >> "who" and "sort" to create a list of a sorted, logged-in users that >> belong to a certain group. Can anyone help me make a script that will >> show a list of ONLY the usernames of the logged in users? I've been >> trying for hours and can't get it to display what I want. > > a quick and dirsty version is > who | awk '{print $1}' | sort|uniq I like this method, actually, though sometimes you can use "sort -u" to eliminate a fork+exec. However, I once saw a bug in GNU sort -u. > This one uses 2 processes instead of 4: > > who | awk '!a[$1]++ {print $1}' awk is fine I guess, but I'm not sure this particular awk method works. In this case it's probably not true, but in some cases (especially for large inputs) a pipeline may actually run faster than a monolithic process if you get decent parallelism out of the pipeline. This is probably going to become more and more true as multicore processors catch on. |