[K12OSN] parse from shell comand

Petre Scheie petre at maltzen.net
Wed Feb 15 20:17:12 UTC 2006


for x in <list of login IDs>
do
echo $x
grep $x /etc/passwd|cut -d: -f5
done

This will give you the ID and the full name associated with it, assuming it's in the 
fifth field of /etc/passwd.  <list of login IDs> could be a file, in which case the 
syntax would be

for x in `cat file_with_IDs`
do
echo $x
grep $x /etc/passwd|cut -d: -f5
done

Petre

Doug Simpson wrote:
> How can I make a script that would parse a line in the passwd file to 
> return the full name of a user instead of outputting the entire line?
> 
> purpose: I have logins logged and it sends the login name to a log and it 
> uses the %U (logins via samba to a samba PDC) in the log.  To my knowlege, 
> there is no way to make it return the full name so I want to take the %U 
> and run it through grep or something so it takes the username, finds it in 
> /etc/passwd and returns the full name to be entered into the log instead 
> of the username.
> 
> Cornfussed, yet?
> 
> Thanks!
> 
> Doug Simpson
> Technology Specialist
> DeQueen Public Schools
> DeQueen, AR 71832
> simpsond at leopards.k12.ar.us
> Tux for President!
> 
> _______________________________________________
> K12OSN mailing list
> K12OSN at redhat.com
> https://www.redhat.com/mailman/listinfo/k12osn
> For more info see <http://www.k12os.org>
> 




More information about the K12OSN mailing list