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}'
   end
   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.
 
omermahAsked:
Who is Participating?
 
ecwConnect With a Mentor Commented:
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
0
 
ecwCommented:
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

0
 
omermahAuthor Commented:
i am getting arror at
 ((getline < "/etc/passwd") > 0)
it is because of > 0
0
 
omermahAuthor Commented:
ecw is great. His reponse to the queation is fast. And most important the soluation is perfect.
Omer Mahmood
0
All Courses

From novice to tech pro — start learning today.