Using awk to do database queries 
Author Message
 Using awk to do database queries



Quote:
>I need help with a script to do queries of a genealogy
>database. The database contains people's names and
>dates/places of birth and death. Following is an example
>of what 2 records might look like:


>1 NAME John Q. Public
>1 SEX M
>1 BIRTH
>2 DATE 1 JAN 1800
>2 PLACE Philadelphia, Pennsylvania
>1 DEATH
>2 DATE 31 DEC 1875
>2 PLACE New York, New York

>1 NAME Jane Doe
>1 SEX F
>1 BIRTH
>2 PLACE Chicago, Illinois

>As you can see from the second record, sometimes the date
>or place may be missing for a birth/death event or sometimes
>the entire event may be missing (for lack of data).

>I would like to write a script which, for 3 given values:
>a) event (birth or death)
>b) event year
>c) event state
>will find the matching records and output the individual's name
>and date/place of the event.
>(For example: Find all births in 1850 in Ohio.)

>I have already written 2 awk programs which find matches for 2 values:
>1) event (birth or death) and place (For example: Find all births in
>Ohio.)
>2) event (birth or death) and date  (For example: Find all births in
>1850.)

>Unfortunately, I can't seem to manage writing an awk program for
>matching
>the 3 values at the same time. I would appreciate any help that anyone
>is
>able to provide.

>Best regards,
>Kevin Outman

If you want an AND of the two, why not just pipe the output of the
first script into the second script.

Am I missing something?

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Wed, 29 May 2002 03:00:00 GMT  
 Using awk to do database queries


% I would like to write a script which, for 3 given values:
% a) event (birth or death)
% b) event year
% c) event state
% will find the matching records and output the individual's name
% and date/place of the event.
% (For example: Find all births in 1850 in Ohio.)

[able to do event & time or event & place, but not all three]

It might be helpful to know how you're approaching it. I would
have something like this:

 /^0/ { if (date == wanted_date && place == wanted_place) print_it()
        clear_it()
      }
      { save_it($0) }
 $1 == 1 && $2 == wanted_event { save_things = 1 }
 $1 == 1 && $2 != wanted_event { save_things = 0 }
 save_things && $1 == 2 && $2 == "DATE" { date = $5 }
 save_things && $1 == 2 && $2 == "PLACE" { split($0,f,/, +/); place = f[2] }
 function print_it() { for (i = 1; i <= things; i++) print thing[i] {
 function clear_it() { delete thing; things = 0; date = place = "" }
 function save_it(val) { thing[++things] = val }

which probably solves the problem but might not fit in with your framework.
--

Patrick TJ McPhee
East York  Canada



Wed, 29 May 2002 03:00:00 GMT  
 Using awk to do database queries
I need help with a script to do queries of a genealogy
database. The database contains people's names and
dates/places of birth and death. Following is an example
of what 2 records might look like:

1 NAME John Q. Public
1 SEX M
1 BIRTH
2 DATE 1 JAN 1800
2 PLACE Philadelphia, Pennsylvania
1 DEATH
2 DATE 31 DEC 1875
2 PLACE New York, New York

1 NAME Jane Doe
1 SEX F
1 BIRTH
2 PLACE Chicago, Illinois

As you can see from the second record, sometimes the date
or place may be missing for a birth/death event or sometimes
the entire event may be missing (for lack of data).

I would like to write a script which, for 3 given values:
a) event (birth or death)
b) event year
c) event state
will find the matching records and output the individual's name
and date/place of the event.
(For example: Find all births in 1850 in Ohio.)

I have already written 2 awk programs which find matches for 2 values:
1) event (birth or death) and place (For example: Find all births in
Ohio.)
2) event (birth or death) and date  (For example: Find all births in
1850.)

Unfortunately, I can't seem to manage writing an awk program for
matching
the 3 values at the same time. I would appreciate any help that anyone
is
able to provide.

Best regards,
Kevin Outman



Thu, 30 May 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Using Query Wizard with a large database

2. querying a database in AOLServer using a tcl-script

3. Wanted : boiler plate example of using python to query a database

4. Outputting info from awk and using the info to name the awk output file

5. Changing date format when doing MySQL query?

6. PIL+Tkinter query (I must be doing something _really_ stupid)

7. Query: What am I doing wrong?

8. Can this be done in AWK?

9. How is this done in awk/nawk/gawk?

10. Can this be done with AWK or ED ?

11. MySQL query in PHP: Not query zero amounts also removes null amounts from query

12. Awk code query

 

 
Powered by phpBB® Forum Software