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 207intmain(argc, argv)int argc;char **argv;{struct passwd *p;}while ((p = getpwent()) != NULL)printf("%s:%s:%ld:%ld:%s:%s:%s\n",p->pw_name, p->pw_passwd, (long) p->pw_uid,(long) p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell);endpwent();return 0;If you don’t understand C, don’t worry about it. The output from pwcat is the userdatabase, in the traditional ‘/etc/passwd’ format of colon-separated fields. The fields are:Login nameThe user’s login name.Encrypted passwordUser-IDGroup-IDFull nameHome directoryThe user’s encrypted password. This may not be availableon some systems.The user’s numeric user ID number.The user’s numeric group ID number.The user’s full name, and perhaps other informationassociated with the user.The user’s login (or “home”) directory (familiar toshell programmers as $HOME).Login shellThe program that is run when the user logs in. Thisis usually a shell, such as bash.A few lines representative of pwcat’s output are as follows:$ pwcat⊣ root:3Ov02d5VaUPB6:0:1:Operator:/:/bin/sh⊣ nobody:*:65534:65534::/:⊣ daemon:*:1:1::/:⊣ sys:*:2:2::/:/bin/csh⊣ bin:*:3:3::/bin:⊣ arnold:xyzzy:2076:10:Arnold Robbins:/home/arnold:/bin/sh⊣ miriam:yxaay:112:10:Miriam Robbins:/home/miriam:/bin/sh⊣ andy:abcca2:113:10:Andy Jacobs:/home/andy:/bin/sh...

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

Saved successfully!

Ooh no, something went wrong!