Home > Archive > Unix Programming > September 2006 > Shell program : Get Emails
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Shell program : Get Emails
|
|
|
| I am trying to write a program decribed below using any shell.
Can anyone suggest wich shell is better?
The program takes one argument <file> that contains a set of lines.
Each line starts with last name of a person followed by the first and
possibly other given names.
The program uses the <file> and the UNIX password file (PassFile) to
produce three files:
<file>-NameEmailList
<file>-EmailList
<file>-NotFoundList
For example:
% getmails InputFile
Produces:
the following 3 files:
InputFile-NameEmailList
InputFile-EmailList
InputFile-NotFoundList
The procedure is as given below:
=D8 For a given person P, search the PassFile for a match of both the
first and last name.
If there is exactly one match, insert the information of P into:
<file>-NameEmailList & <file>-EmailList.
=D8 Otherwise, search for a match of either the first or the last
name.
If there is at least one match, ask the user to select the right match.
If the user selects a match, insert the information of P into:
<file>-NameEmailList & <file>-EmailList.
=D8 If there is no match or the user did not select any mach, then
insert P's name into:
<file>-NotFoundList
---------------------------------------------------------------------------=
---------------------------------------------------
This is the program I am trying to write ....
Can anyone give me an idea regarding this one .
Thanx in advance.
| |
| Chris F.A. Johnson 2006-09-21, 10:00 pm |
| On 2006-09-20, mano wrote:
> I am trying to write a program decribed below using any shell.
>
> Can anyone suggest wich shell is better?
Any POSIX shell (bash, ksh, ash, ...) will probably do the job.
> The program takes one argument <file> that contains a set of lines.
> Each line starts with last name of a person followed by the first and
> possibly other given names.
In what format?
> The program uses the <file> and the UNIX password file (PassFile) to
> produce three files:
><file>-NameEmailList
><file>-EmailList
><file>-NotFoundList
> For example:
> % getmails InputFile
> Produces:
> the following 3 files:
>
> InputFile-NameEmailList
> InputFile-EmailList
> InputFile-NotFoundList
>
> The procedure is as given below:
>
> Ø For a given person P, search the PassFile for a match of both the
> first and last name.
>
> If there is exactly one match, insert the information of P into:
>
><file>-NameEmailList & <file>-EmailList.
>
>
> Ø Otherwise, search for a match of either the first or the last
> name.
>
> If there is at least one match, ask the user to select the right match.
ITYM, more than one match.
> If the user selects a match, insert the information of P into:
>
><file>-NameEmailList & <file>-EmailList.
>
>
> Ø If there is no match or the user did not select any mach, then
> insert P's name into:
>
><file>-NotFoundList
This should get you started:
LF=$'\n'
while read last first middle
do
user=$( grep -e "$last.*$first" /etc/password )
case $user in
*"$LF"*) select_user ;; ## write a function for the selection
*) printf "%s\n" "$user" >> "$1-EmailList"
done < "$1"
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
|
|
|
|
|