home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / shellfiles / edtable < prev    next >
Encoding:
Text File  |  1988-03-28  |  1.3 KB  |  60 lines

  1. # Edtable edits the mmdf database using dbmedit.  Usage is
  2. #
  3. # edtable table_name old_file new_file
  4. #
  5. # where table_name is the name of the mmdf table,  old_file  is  the  current
  6. # file  from  which  table_name is built, and new_file is the data we want in
  7. # the table now.  Edtable  compares  old_file  with  new_file  and  generates
  8. # appropriate add/change/delete commands for dbmedit. Edtable copies new_file
  9. # on top of old_file and deletes new_file.
  10. #
  11. # Don't try to update very large (eg pathalias) tables with this.  You
  12. # might as well run dbmedit because the seds and awks are slow.  This
  13. # is designed to fix small tables in a large database.
  14. #
  15. #                                 Steve Losen <scl@virginia.acc.virginia.edu>
  16.  
  17. AWKPROG='
  18. BEGIN {
  19.     q="\""
  20.     tname="'$1'"
  21. }
  22. $1 != key {
  23.     if (key) {
  24.         if (edit == "delete")
  25.             print edit, q key q, tname
  26.         else
  27.             print edit, q key q, tname, q value q
  28.     }
  29.     key=$1
  30.     value=$2
  31.     if ($3 == "old")
  32.         edit="delete"
  33.     else
  34.         edit="add"
  35.     next
  36. }
  37. value == $2 {
  38.     key = ""
  39.     next
  40. }
  41. {
  42.     edit = "change"
  43.     if ($3 == "new") value = $2
  44. }
  45. END {
  46.     if (key) {
  47.         if (edit == "delete")
  48.             print edit, q key q, tname
  49.         else
  50.             print edit, q key q, tname, q value q
  51.     }
  52. }' 
  53.  
  54. {
  55.     sed -e 's/["\]/\\&/g' -e "s/$/:old/" $2
  56.     sed -e 's/["\]/\\&/g' -e "s/$/:new/" $3
  57. } | sort | awk -F: "$AWKPROG" | /usr/mmdf/table/dbmedit > /dev/null
  58. /bin/cp $3 $2
  59. /bin/rm -f $3
  60.