home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / question / 10419 < prev    next >
Encoding:
Internet Message Format  |  1992-08-26  |  3.1 KB

  1. Path: sparky!uunet!sun-barr!ames!elroy.jpl.nasa.gov!usc!news
  2. From: rpinder@phad.hsc.usc.edu (Rich Pinder)
  3. Newsgroups: comp.unix.questions
  4. Subject: AWK - calculate check sum for zip+4....
  5. Date: 26 Aug 1992 21:32:01 -0700
  6. Organization: University of Southern California, Los Angeles, CA
  7. Lines: 95
  8. Sender: rpinder@phad.hsc.usc.edu (Rich Pinder)
  9. Distribution: world
  10. Message-ID: <l9omm1INN9be@phad.hsc.usc.edu>
  11. NNTP-Posting-Host: phad.hsc.usc.edu
  12.  
  13. HELP!
  14.  
  15. You know the saying 'nothing changes, but everything changes' ....
  16.  
  17. I had a code segment working fine in an AWK script to calculate a
  18. Zip-plus-4 check code for use with a barcoding project.  Then I
  19. lifted the same segment, changed the referenced variables (in the
  20. original I was substr(ing) the $0, and now i'm referring to the
  21. variable as $5) but am now getting some strange error - looks like my
  22. calculated variable (check) isn't getting reset after each iteration
  23. of the step:
  24.  
  25.  
  26. stand-alone code segment that DOEWN't work:
  27.  
  28. awk -F '|' '    {         
  29.         OFS="|";
  30.         for (i=1; i<=length($5); i++)
  31.         a += substr($5,i,1);
  32.         check=10-(a-(10*(substr(a,1,1))));
  33.         if (check==10) check=0;
  34.  
  35.  
  36.         print($1,$2,$3,$4,$5,check,$7);
  37.  
  38.         } ' $*
  39.  
  40.  
  41. ......
  42. sample of the input file:
  43.  
  44. 73203587 | |738 W GOLDEN ST # 5 |LOS ANGELES CA 90017 |90017 |3|1
  45. 60120617 | |2785 PACIFC CST HWY |TORRANCE CA 90505 |90505 |1|1
  46. 60120618 | |2785 PACIFC CST HWY |TORRANCE CA 90505 |90505 |1|1
  47. 61127392 | |2717 VIA ACORONA |MONTEBELLO CA 90640 |90640 |1|1
  48. 47051664 | |CYM BERTH 202 #17 |WILMINGTON CA 90744 |90744 |6|2
  49. 60120233 | |938 COLIMA |AZUSA CA 91702 |91702 |1|1
  50. 58106166 | |3726 FOSTER |BALDWIN PARK CA 91706 |91706 |7|1
  51. 49059900 | |2395 F |CARLSBAD CA 92009 |92009 |0|1
  52. 57097895 | |10737 S D MSN RD # 105 |SAN DIEGO CA 92108 |92108 |0|1
  53. 62135984 | |512 S ROSWELL ST |SAN DIEGO CA 92114 |92114 |3|1
  54. 73203587 | |738 W GOLDEN ST # 5 |LOS ANGELES CA 90017 |90017 |3|1
  55.  
  56.  
  57. sample of the output file (see $6 in line 5):
  58.  
  59. 60120617 | |2785 PACIFC CST HWY |TORRANCE CA 90505 |90505 |4|1
  60. 60120618 | |2785 PACIFC CST HWY |TORRANCE CA 90505 |90505 |5|1
  61. 61127392 | |2717 VIA ACORONA |MONTEBELLO CA 90640 |90640 |6|1
  62. 47051664 | |CYM BERTH 202 #17 |WILMINGTON CA 90744 |90744 |2|2
  63. 60120233 | |938 COLIMA |AZUSA CA 91702 |91702 |-97|1
  64. 58106166 | |3726 FOSTER |BALDWIN PARK CA 91706 |91706 |-120|1
  65. 49059900 | |2395 F |CARLSBAD CA 92009 |92009 |-140|1
  66. 57097895 | |10737 S D MSN RD # 105 |SAN DIEGO CA 92108 |92108 |-160|1
  67. 62135984 | |512 S ROSWELL ST |SAN DIEGO CA 92114 |92114 |-177|1
  68.  
  69.  
  70. heres a code section that DID work just fine
  71. ...stuff deleted
  72.     {
  73.  
  74.     zipplus=substr($0,469,9);
  75.     addform=substr($0,486,30);
  76.     cityform=substr($0,516,30);
  77. #  Calculate the check digit, and output as seperate (6th) variable
  78.         for (i=1; i<=length(zipplus); i++)
  79.         a += substr(zipplus,i,1);
  80.         check=10-(a-(10*(substr(a,1,1))));
  81.         if (check==10) check=0;
  82.  
  83. print(id,name,addform,cityform,zipplus,check) > "caltwin.mail";
  84.     }
  85.  
  86. ......stuff deleted
  87.  
  88.  
  89.  
  90.  
  91. Its late, i'm behind a deadline, and it may be something very simple....
  92.  
  93. I appreciate any thoughts you have....
  94.  
  95.  
  96.  
  97.         Rich Pinder
  98.         USC School of Medicine
  99.         (213) 342-1640
  100.  
  101.         rpinder@usc.edu
  102.  
  103.     ||||||||||||||||||||||||||||||||||||||||||||||||||
  104. -- 
  105.  
  106.  
  107. Rich
  108.