>> GECOS=`cat /etc/passwd | grep $USERNAME | cut -f5 -d:`
> Hey, cool! This is really great (and now I should start reading
> 'man cut', I love this learning gig) but it includes the "other"
> information (ie: office, telephone numbers) which come after the
> comma. Argh. Hmm...? :)

Pass it through another cut, then, so like:

GECOS=`grep $USERNAME /etc/passwd | cut -f5 -d: | cut -f1 -d,`

Note that you need to fiddle with it a bit if your GECOS entries are of
the form Last, First Middle, Lots-of-other-data. In that case, you can cut
-f1-2 -d, instead. =)

Of course, there are a million ways to do this. There's

GECOS=`awk -F : "/^$USERNAME\:/ { print \$5 }" < /etc/passwd`

.. then pass that through anything that extracts the name. =) Even awk,
which can also handle rearranging names. Isn't it sooo cool?

Sacha 8)


_
Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph
To leave: send "unsubscribe" in the body to [EMAIL PROTECTED]

To subscribe to the Linux Newbies' List: send "subscribe" in the body to 
[EMAIL PROTECTED]

Reply via email to