Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finger and usernames

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

I have a file which contains a list if usernames and I would like to get a new file with columns like

"username" "In real life" (output from finger -m "username")

Many thanks!

 
man awk

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Try
Code:
for u in $(cat usernamelist)
do
  echo $u is in real life $(awk -F : '/'"$u"'/{print $5}' /etc/passwd)
done >> userlistwithfullnames

Columb Healy
 
Another way:
man join

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I can use /etc/password

I need something like that but this gives syntax error
Code:
#!/usr/bin/csh 

for u in $(cat usernamelist)
do
  echo $u is in real life finger -m $u | awk '{ if (NR==1) {print $7 $8} }'
done >> userlistwithfullnames
 
You need to get the output of the finger. There are two options
Code:
for u in $(cat usernamelist)
do
  echo $u is in real life $(finger -m $u | awk '{ if (NR==1) {print $7 $8} }')
done >> userlistwithfullnames
or
Code:
for u in $(cat usernamelist)
do
  echo "$u is in real life \c"
  finger -m $u | awk '{ if (NR==1) {print $7 $8} }'
done >> userlistwithfullnames

Columb Healy
 
#!/usr/bin/csh
Why using so buggy shell ?


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV

Thanks for pointing that out - I beleive the $(command) syntax I've used only works under ksh.

Columb Healy
 
PHV why are you so angry?

Anyways I did the following script based on Columb's:

Code:
#!/usr/bin/ksh 

#create usersnamelist
ls -l /users | awk '{print $3}' | sort -u > /tmp/usernamelist

# process list to get real life name
for u in $(cat /tmp/usernamelist)
do
  echo "$u is in real life \c"
  finger -m $u | awk '{ if (NR==1) {print $7 " " $8} }'
done >> userlistwithfullnames

#cleanup
rm -f /tmp/usernamelist

However for some users finger -m returns In real life: # some name but for other I get In real life:toto.titi@tt.com

is there a way to extract the full name after # and toto titi depending on the case?

 
I'm not angry, I just pointed out that ksh-like syntax is not advisable for csh and that csh is deprecated since a while ...
 
fabien

You don't need to use the temporary file
Code:
for u in $(ls -l /users | awk '{print $3}' sort -u )
do
  echo "$u is in real life \c"
  finger -m $u | awk '{ if (NR==1) {print $7 " " $8} }'
done >> userlistwithfullnames
To deal with the different cases you need to look at the awk syntax, as PHV says 'man awk'. This is quite a maor topic and has it's own forum. As finger is getting this info from /etc/passwd why don't you cut out the middleman and use awk to get it directly?

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top