#!/bin/bash # This is the shell script to be constructed in Exercise 2 # of Module 3. Depending on the number of gid's at your site # you made need to pipe the output of this script to 'more' # or 'less'. My group is 100; you may need to use a # different number. # David Harrison, May 2002 echo -n "Number of users in group 100 (Method 1): " cat /etc/passwd | cut -d: -f4 | grep '^100$' | # We guard against matching say "1000" wc -l echo -n "Number of users in group 100 (Method 2): " grep '^.*:.*:.*:100:' /etc/passwd | wc -l # Put out a blank line so it looks nice on the screen. echo echo "All gids sorted by number (number gid):" echo # Another blank line cat /etc/passwd | # Putting each separate command on a cut -d: -f4 | # new line, as here, is usually considered sort | # to make the script more readable. uniq -c | sort -n echo echo "All gids sorted by gid (number gid): " echo cat /etc/passwd | cut -d: -f4 | sort | uniq -c | sort -n -k2 echo echo "All gids sorted by gid (gid number):" echo cat /etc/passwd | cut -d: -f4 | sort | uniq -c | sort -n +1 | # This is equivalent to "sort -n -k2" above. awk ' { print $2, $1 } '