C SHELL !!!!

  Each  user on (nias) unix server is placed in a primary group which is determined by the group id number in the file      /etc/passwd   Users may be placed in additional  groups by placing their login name in  the file     /etc/group.
   Write a shell script  list C  which lists the login name and the full name description of each user who is in the group   cstaff.

   awk -F: '/cstaff/{print $4}' /etc/group \
   | awk -F, '{for(i=1;i<=NF;i++) print $i}' > temp.txt
   echo 'from group  ----------  from passwd'
   echo ''
   foreach names (`cat temp.txt`)
      echo '  '
      echo -n ${names} "          "
      grep -w ${names} /etc/passwd | awk -F: '{print $5}'
   rm temp.txt

I have done it by reading the  /etc/group file using awk and the users in the ccstaff group are listed to a file.  This file is then read and each name is then searched for in the file /etc/passwd using a combination of grep and awk.
But can this be done without using a file. For eaxmple can the output of awk be written to setings and then one can compare the strings.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

grep '^cstaff:' /etc/group |  cut -d: -f4- | tr ',' '\n' | sort -u | awk -F: '/./
 { uname[$1]  =  $1; } END { while ((getline < "/etc/passwd") > 0) { if (uname[$
1] == $1) { printf("%8s\t%s\n", $1,  $5); } } }' | sort -u

omermahAuthor Commented:
i am getting arror at
 ((getline < "/etc/passwd") > 0)
it is because of > 0
the whole thing meant to be a single line - csh doesn't like embedded newlines.  Maybe getline is nawk'ism, if so, replace 'awk' with 'nawk' (or gawk even).

Prettified, it's ...

grep '^cstaff:' /etc/group |  cut -d: -f4- | tr ',' '\n' | sort -u |           \
        awk -F: '/./{ uname[$1]  =  $1; }                                     \
                END { while ((getline < "/etc/passwd") > 0) {                 \
                        if (uname[$1] == $1) {                                \
                                printf("%8s\t%s\n", $1,  $5);                 \
                        }                                                           \
                     }                                                              \
                }' | sort -u

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
omermahAuthor Commented:
ecw is great. His reponse to the queation is fast. And most important the soluation is perfect.
Omer Mahmood
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.