All pastes #446513 Raw Edit

HeatHawk

public text v1 · immutable
·published 2007-04-18 15:19 UTC
rendered paste body

As you know, both bash and awk can be called from within each other. For
building
general applications/filters, it is a good idea to use the language that
has specific strengths for the functionality you need. For the following
problem
you will need to use both bash and awk in order to accomplish the task
in an
easy manner.

You will create an application that is essentially a bash script that
will call
an awk script. The application is called "lookup." It will have the
following
options: -a to look up by the account name, -u to look up by the UID
(note that
all students are UID 503, while staff are numbers other than 503), and
-n
to look up by the users last name. For example,
 lookup -a ungers
will look in the passwd file (the network one, not the local one) and
find the
account with ungers as the account name.

If the search finds a single match, display the user's full name and
their
home path. If there are multiple matches display the all the data in a
raw format.

Examples: The previous command (lookup -a ungers) will show:
 NAME: Shawn Unger    PATH: /home/ungers

while the command: lookup -u 503 would find all the students formatted
as follows:
 bagg0011:x:2477:503:BAGGOO SHANE:/home/bagg0011:/bin/bash
 drai0006:x:2256:503:DRAINVILLE ERICK:/home/drai0006:/bin/bash
 goss0047:x:2535:503:GOSSET NORMAN:/home/goss0047:/bin/bash
 azzi0016:x:2649:503:AZZI DAVID:/home/azzi0016:/bin/bash
 lyon0051:x:2551:503:LYONS SCOTT:/home/lyon0051:/bin/bash
 tche0007:x:1985:503:TCHEKANSKY ALEXEI:/home/tche0007:/bin/bash
 ... etc

NOTE:
 If nothing was found, display an appropriate message.

HINT: Use bash to process the command line and awk to perform the actual
searching.