Obtaining Input from Text Files
As you might have already guessed, the default manner in which awk operates is to read a file line-by-line, searching for the specified pattern in each line. When it finds a line that contains the specified pattern, it will perform the specified action on that line. Let’s begin by building upon the passwd file example that I showed you in the previous section.
Looking for Human Users
The /etc/passwd file contains a list of all users on the system. What I’ve always found curious is that system user accounts and normal human user accounts are all mixed together in the same file. But, let’s say that as part of your administrator duties, you need to maintain a list of normal human users on each machine. One way to do that is to use awk to search through the passwd file for the User ID Numbers (UIDs) that correspond to human users. To find out what the UID numbers for normal users are, you can look in the /etc/login.defs file...