21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 12: A Library of awk Functions 211putchar(’\n’);}endgrent();return 0;}Each line in the group database represents one group. The fields are separated withcolons and represent the following information:Group name The group’s name.Group passwordGroup-IDThe group’s encrypted password. In practice, this fieldis never used; it is usually empty or set to ‘*’.The group’s numeric group ID number; this numbershould be unique within the file.Group member list A comma-separated list of user names. These usersare members of the group. Modern Unix systems allowusers to be members of several groups simultaneously.If your system does, then there are elements"group1" through "groupN" in PROCINFO for thosegroup ID numbers. (Note that PROCINFO is a gawk extension;see Section 6.5 [Built-in Variables], page 110.)Here is what running grcat might produce:$ grcat⊣ wheel:*:0:arnold⊣ nogroup:*:65534:⊣ daemon:*:1:⊣ kmem:*:2:⊣ staff:*:10:arnold,miriam,andy⊣ other:*:20:...Here are the functions for obtaining information from the group database. There areseveral, modeled after the C library functions of the same names:# group.awk --- functions for dealing with the group fileBEGIN \{# Change to suit your system_gr_awklib = "/usr/local/libexec/awk/"}function _gr_init({if (_gr_inited)returnoldfs, oldrs, olddol0, grcat,using_fw, n, a, i)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!