#!/usr/bin/awk -f # @(#) name.awk 1.2 92/05/02 # 90/06/01 john h. dubois iii (john@armory.com) # 90/11/14 removed ksh-specific code # 91/06/30 removed dependency on having variable assignments given # on awk command line set before execution of BEGIN block # (doesn't work in some awks) # 91/12/07 added PATH setting, # added code to get rid of phone number in GCOS field # 92/05/02 converted to #!awk script BEGIN { if (ARGC < 2) { print \ "name: give users' real names from /etc/passwd.\n" \ "Usage: name [ ... ]\n" \ "The real(?) name of each , as recorded in /etc/passwd, is printed,\n" \ "in the format\n" \ "\n" \ "userreal-name\n" \ "\n" \ "Full regular expressions can be used if escaped from the shell.\n" \ "For example,\n" \ "\n" \ "name \".*\"\n" \ "\n" \ "will print a list of the names of every user on the system." exit(0) } FS = ":" names = "^(" ARGV[1] for (i = 2; i < ARGC; i++) names = names "|" ARGV[i] names = names ")$" while ((getline < "/etc/passwd") == 1) if ($1 ~ names) { sub(",.*","",$5) # get rid of phone number, if any printf("%8s %s\n",$1,$5) } }