Subject: scripts for working with .addressbook

From: Mike Miller <[email-masked]>
Date: Sat, 18 Sep 1999 14:43:15 -0500 (CDT)

Unix users:

I wrote a couple of scripts (tcsh for Solaris, but you can easily modify
them for your system) that have been very helpful to me and I want to
share them with the rest of you.  The two scripts are appended at the end
of this message.  I call the first one 'person' and I call the second one
'comment'.  I put them in our system in /usr/local/bin These scripts are
used to grab records out of the ~/.addressbook database.  For example:

# person Johnson

ericjohn        Johnson, Eric   [email-masked]
   from NIDA.  Did item heritability analyses.

johnsonf        Johnson, Fred   [email-masked]

johnsong        Johnson, Greg   [email-masked]
   IATS guy, does Solaris, Unix, (573) 882-5008

The command "person Johnson" found three records containing the string
'Johnson' in either the nickname, fullname or address field and it wrote
the lines showing me the full record on each person including the comments
field.

Another example:

# comment 1485

kristiej        Jackson, Kristina       [email-masked]
   office: (573) 884-1485,  home: (573) 817-2940

The command "comment 1485" searched for comments containing '1485' and
returned all the fields in that record.

These commands almost always work for me, but they are not perfect.  Not
all records are parsed by the rules I implicitly assume in these
simple-minded scripts.

It would be fantastic if someone could do it right!  I would love to have
a perl script, or whatever, that would deal with the exact structure of
~/.addressbook and always give me what I want.  It is probably a very easy
perl programming job, but I'm not competent enough to pull it off.

Regards,

Mike

Michael B. Miller, M.S., Ph.D., M.P.E.
Department of Psychology
University of Missouri--Columbia
Columbia, MO 65211
http://taxa.psyc.missouri.edu/~mbmiller/

----------------------------------------------------------------------

The 'person' script.
To grab records with some string in another (non-comment) field:

#!/usr/local/bin/tcsh -f
foreach N ( `egrep -n "$1" ~/.addressbook | egrep -v ':   ' | awk -F: '{print $1}'` )
tail +$N ~/.addressbook | head -1 | fmt -w 75
tail +$N ~/.addressbook | tail +2 | head -1 | egrep '^   ' | fmt -w 75
echo ""
end

The 'comment' script.
To grab records with some string in the comment field:

#!/usr/local/bin/tcsh -f
foreach N ( `egrep -n "$1" ~/.addressbook | egrep ':   ' | awk -F: '{print $1 - 1}'` )
tail +$N ~/.addressbook | head -2 | fmt -w 75
echo ""
end

-- 
-----------------------------------------------------------------
 For information about this mailing list, and its archives, see: 
 http://www.washington.edu/pine/pine-info/
-----------------------------------------------------------------