home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!ames!elroy.jpl.nasa.gov!usc!news
- From: rpinder@phad.hsc.usc.edu (Rich Pinder)
- Newsgroups: comp.unix.questions
- Subject: AWK - calculate check sum for zip+4....
- Date: 26 Aug 1992 21:32:01 -0700
- Organization: University of Southern California, Los Angeles, CA
- Lines: 95
- Sender: rpinder@phad.hsc.usc.edu (Rich Pinder)
- Distribution: world
- Message-ID: <l9omm1INN9be@phad.hsc.usc.edu>
- NNTP-Posting-Host: phad.hsc.usc.edu
-
- HELP!
-
- You know the saying 'nothing changes, but everything changes' ....
-
- I had a code segment working fine in an AWK script to calculate a
- Zip-plus-4 check code for use with a barcoding project. Then I
- lifted the same segment, changed the referenced variables (in the
- original I was substr(ing) the $0, and now i'm referring to the
- variable as $5) but am now getting some strange error - looks like my
- calculated variable (check) isn't getting reset after each iteration
- of the step:
-
-
- stand-alone code segment that DOEWN't work:
-
- awk -F '|' ' {
- OFS="|";
- for (i=1; i<=length($5); i++)
- a += substr($5,i,1);
- check=10-(a-(10*(substr(a,1,1))));
- if (check==10) check=0;
-
-
- print($1,$2,$3,$4,$5,check,$7);
-
- } ' $*
-
-
- ......
- sample of the input file:
-
- 73203587 | |738 W GOLDEN ST # 5 |LOS ANGELES CA 90017 |90017 |3|1
- 60120617 | |2785 PACIFC CST HWY |TORRANCE CA 90505 |90505 |1|1
- 60120618 | |2785 PACIFC CST HWY |TORRANCE CA 90505 |90505 |1|1
- 61127392 | |2717 VIA ACORONA |MONTEBELLO CA 90640 |90640 |1|1
- 47051664 | |CYM BERTH 202 #17 |WILMINGTON CA 90744 |90744 |6|2
- 60120233 | |938 COLIMA |AZUSA CA 91702 |91702 |1|1
- 58106166 | |3726 FOSTER |BALDWIN PARK CA 91706 |91706 |7|1
- 49059900 | |2395 F |CARLSBAD CA 92009 |92009 |0|1
- 57097895 | |10737 S D MSN RD # 105 |SAN DIEGO CA 92108 |92108 |0|1
- 62135984 | |512 S ROSWELL ST |SAN DIEGO CA 92114 |92114 |3|1
- 73203587 | |738 W GOLDEN ST # 5 |LOS ANGELES CA 90017 |90017 |3|1
-
-
- sample of the output file (see $6 in line 5):
-
- 60120617 | |2785 PACIFC CST HWY |TORRANCE CA 90505 |90505 |4|1
- 60120618 | |2785 PACIFC CST HWY |TORRANCE CA 90505 |90505 |5|1
- 61127392 | |2717 VIA ACORONA |MONTEBELLO CA 90640 |90640 |6|1
- 47051664 | |CYM BERTH 202 #17 |WILMINGTON CA 90744 |90744 |2|2
- 60120233 | |938 COLIMA |AZUSA CA 91702 |91702 |-97|1
- 58106166 | |3726 FOSTER |BALDWIN PARK CA 91706 |91706 |-120|1
- 49059900 | |2395 F |CARLSBAD CA 92009 |92009 |-140|1
- 57097895 | |10737 S D MSN RD # 105 |SAN DIEGO CA 92108 |92108 |-160|1
- 62135984 | |512 S ROSWELL ST |SAN DIEGO CA 92114 |92114 |-177|1
-
-
- heres a code section that DID work just fine
- ...stuff deleted
- {
-
- zipplus=substr($0,469,9);
- addform=substr($0,486,30);
- cityform=substr($0,516,30);
- # Calculate the check digit, and output as seperate (6th) variable
- for (i=1; i<=length(zipplus); i++)
- a += substr(zipplus,i,1);
- check=10-(a-(10*(substr(a,1,1))));
- if (check==10) check=0;
-
- print(id,name,addform,cityform,zipplus,check) > "caltwin.mail";
- }
-
- ......stuff deleted
-
-
-
-
- Its late, i'm behind a deadline, and it may be something very simple....
-
- I appreciate any thoughts you have....
-
-
-
- Rich Pinder
- USC School of Medicine
- (213) 342-1640
-
- rpinder@usc.edu
-
- ||||||||||||||||||||||||||||||||||||||||||||||||||
- --
-
-
- Rich
-