how to extract fields for /etc/passwd

hi,

i would like to extract the just name field from /etc/passwd file, and nothing else. ie grep pauline, and Pauline Fowler comes back.

cheeers
paul mc

PASSWORD_FILE=/etc/passwd
n=1
for name in $(awk 'BEGIN{FS=":"}{print $1}' < "$PASSWORD_FILE" )
do
   echo "USER #$n = $name"
   (( n += 1 ))
done

Regards

hi there are easier ways..

just found this

cat /etc/passwd | awk -F ":" '{print $6}' #this displays 6th field ie home directories

awk -F\: '{print $6}' /etc/passwd |grep pauline #this displays pauline home directory

or echo ~pauline.fowler

u can use the cut to extract the field required..this case the fifth field(try to check to make sure that urs system is using the same format for passwd file)and then u can use the grep command to find the user name
cut -d':' -f5 /etc/passwd |grep nameulookingfor
or u can use grep nameulookingfor /etc/passwd | cut -d':' -f5 ...

may be awk users can provide with more options...using the print{$5} options....

thanks
klashxx that was really useful

Hi,

   When i run the following  shell its giving an errorin line 5 ? syntax error $' unexpected

What is the error???

#!/bin/sh
log=/u01//userlist.log
PASSWORD_FILE=/etc/passwd
n=1
for name in $(awk 'BEGIN{FS=":"}{print $1}' < "$PASSWORD_FILE" )
do
echo "USER #$n = $name" > $log
(( n += 1 ))
done

Many Thanks,

change #!/bin/sh

to

#!/bin/ksh