1 : "see_edf.ksh by Dan Martin (DRM/CTG) 04-20-2000" 2 # Reads files like kyowc_20000323_003406.edf (OMNI-related) 3 function _usage 4 { 5 cat << BOX 6 7 Usage: $1 omnifile.edf [V|T] 8 9 Where: "omnifile.edf" is a valid pathname to an 10 OMNI Express type datafile ending in .edf 11 12 And: V = Verbose Mode (shows some info for every record) 13 T = Terse Mode (default) 14 15 Action: Analyzes and reports stats on the file. 16 17 BOX 18 exit 19 } # EOF _usage() 20 function _dang 21 { 22 cat << BOX 23 24 Program $1 terminated! 25 26 $2 27 28 BOX 29 exit 30 } # EOF _dang() 31 [[ -z "$1" ]] && _usage "$0" 32 [[ -f "$1" ]] || _dang "$0" "Could not find file \"$1\"!" 33 [[ -z "$2" ]] && way=T || way=$2 34 # echo "\nNow processing file \"$1\" (${way})...\c" 35 awk -v op="$way" -v fil="$1" ' 36 ## AWK FUNCTIONS: 37 # spc(n) slides n [more] spaces along the current line: 38 function spc(n) {for (i = 0; i < n; i++) printf(" ")} 39 # str(n) prints a bar of n "stars" along the current line: 40 function str(n) {for (i = 0; i < n; i++) printf("*")} 41 # skip(n) jumps to the next line and skips down an additional (n-1) lines: 42 function skip(n) {for (i = 0; i < n; i++) printf("\n")} 43 BEGIN \ 44 {# HEADER RECORD VARIABLES (NR == 1): 45 ornum = "www" # Order Number (Number ??) 46 dof = "xxx" # Date of file MMDDYYYY 47 nrecr = "yyy" # Number of detail records (NR - 1) 48 nrecc = 0 # Num Recs coerced to numeric 49 fsqnr = "zzz" # File Sequence "Number" 50 fsqnc = 0 # FSN coerced to numeric 51 phty = "xx" # Phone Type 52 phonr = "xxx" # Phone Ownership 53 cuid = "xxx" # Customer ID 54 cuid2 = "xxx" # Customer destination/suffix 55 jnum = 1 # Junk Number 56 if (op == "T" || op == "V" ) jnum = 0 57 if (jnum == 1) op = "T" 58 59 # DETAIL RECORD VARIABLES (NR > 1): 60 mlid = "xxx" # Manufacturers Location ID 61 mfnam = "xxx" # Manufacturers name 62 modno = "xxx" # Model Number 63 mdnam = "xxx" # Model Name 64 eqty = "xx" # Equipment Type 65 lork = "xxx" # Lot# or Revision Key 66 esn = "xxx" # Electronic Serial Number 67 imsi = "xxx" # Intl. Mobil Station ID 68 akey = "xxx" # Authentication Key 69 slc1 = "xxx" # Subsidy Lock Code 1 70 slc2 = "xxx" # Subsidy Lock Code 2 71 plc = "xxx" # Phone Lock Code 72 desn = 0 # Decimal ESN 73 svnr = "xxx" # Software Version Number - Raw 74 svnc = 0 # SVN coerced to numeric 75 76 # ARRAYS DEFINED: 77 # tyeq[] = Different Equipment type-counter 78 # nammf[] = Manufacturer Names 79 # nomad[] = Different Model Numbers 80 # aesn[] = ESNs discovered 81 82 # Print File info: 83 printf("\n\n") 84 printf("EDF FILE EXAMINED: \"%s\" (%s)\n\n", fil, op) 85 } 86 # main() 87 {if (NR == 1) # Header Record Position: 88 {ornum = substr($0, 1,20) # 001-020 89 dof = substr($0, 21, 8) # 021-028 90 nrecr = substr($0, 29, 6) # 029-034 91 nrecc = 1 * nrecr 92 fsqnr = substr($0, 35, 6) # 035-040 93 fsqnc = 1 * fsqnr 94 phty = substr($0, 41, 2) # 041-042 95 phonr = substr($0, 43, 4) # 043-046 96 cuid = substr($0, 47,12) # 047-058 97 cuid2 = substr($0, 59, 6) # 059-064 98 # resh = substr($0,176,115) # 065-179 - Reserved 99 tds = sprintf("%2s/%2s/%4s", \ 100 substr(dof,1,2), substr(dof,3,2), substr(dof,5,4)) 101 # Print Header info: 102 printf("\n") 103 printf("ORDER NUMBER FILE DATE COUNT SEQ # ") 104 printf("TY OWNR CUSTOMER ID DESTIN\n") 105 printf("-------------------- ---------- ----- ----- ") 106 printf("-- ---- ------------ ------\n") 107 printf("%-20s %10s %5d %5d ", ornum, tds, nrecc, fsqnc) 108 printf("%2s %4s %12s %6s\n\n", phty, phonr, cuid, cuid2) 109 if (op == "V") 110 {printf("OMNI MODEL NUMBER ESN \n") 111 printf("-------------------- -----------\n") 112 } 113 } 114 else {mlid = substr($0, 1, 3) # 001-003 115 mfnam = substr($0, 4,30) # 004-033 116 modno = substr($0, 34,20) # 034-053 117 mdnam = substr($0, 54,30) # 054-083 118 eqty = substr($0, 84, 2) # 084-085 119 lork = substr($0, 86, 5) # 086-091 120 esn = substr($0, 92,11) # 092-102 121 imsi = substr($0,103,15) # 103-117 122 akey = substr($0,118,26) # 118-143 123 slc1 = substr($0,144, 6) # 144-149 124 slc2 = substr($0,150, 6) # 150-155 125 plc = substr($0,156, 4) # 156-159 126 desn = substr($0,160,11) # 160-170 127 svnr = substr($0,171, 6) # 171-175 128 svnc = 1 * svnr 129 # resd = substr($0,176, 4) # 176-179 - Reserved 130 # Rachet the array counts: 131 ++tyeq[eqty] 132 ++nammf[mfnam] 133 ++nomod[modno] 134 ++aesn[esn] 135 if (op == "V") printf("%-20s %-11s\n", modno, esn) 136 } 137 } 138 END \ 139 { if ((NR -1) != nrecc) 140 {printf("WARNING! RECORD COUNT WRONG! ") 141 printf("Header says %d but actual count is %d!\n\n", nrecc, (NR -1)) 142 } 143 printf("\n") 144 # Print Detail info: 145 for (nam in nammf) printf(" Name: %-30s Count: %4d\n", nam, nammf[nam]) 146 for (ty in tyeq) 147 {printf(" Type: %-2s", ty) 148 spc(32) 149 printf("Count: %4d\n", tyeq[ty]) 150 } 151 for (mod in nomod) 152 {printf("Mod #: %-20s", mod) 153 spc(14) 154 printf("Count: %4d\n", nomod[mod]) 155 } 156 aak = 0 157 for (ct in aesn) 158 {ect += aesn[ct] 159 if (aesn[ct] > 1) 160 {++aak; spc(7) 161 printf("** WARNING: ESN %s HAS %d DUPLICATES! **\n", ct, aesn[ct]) 162 } 163 } 164 # printf("\n") 165 # spc(37) 166 if (aak == 0) {printf("NO DUPLICATE ESNs FOUND!"); spc(13)} 167 else {printf("FOUND %3d ESNs WITH DUPLICATES!", aak); spc(6)} 168 printf("ESN-Count: %4d\n", ect) 169 printf("\n") 170 }' $1 171 # EOF see_edf.ksh ******************* EXAMPLE OUTPUT ******************* The below is the output of see_edf.ksh when run on the data file mungedup.edf ORDER NUMBER FILE DATE COUNT SEQ # TY OWNR CUSTOMER ID DESTIN -------------------- ---------- ----- ----- -- ---- ------------ ------ OmniExpress Alpha 03/23/2000 50 3406 NW OMNI WARNING! RECORD COUNT WRONG! Header says 50 but actual count is 49! Name: Kyocera Wireless Corp. Count: 48 Name: Bozo's Wireless Telegraph Count: 1 Type: CP Count: 45 Type: PU Count: 2 Type: XX Count: 1 Type: HA Count: 1 Mod #: TAEBD00007 Count: 2 Mod #: TAEBD00005 Count: 1 Mod #: TAEBD00004 Count: 1 Mod #: TAEBD00003 Count: 45 ** WARNING: ESN B31D25D7 HAS 3 DUPLICATES! ** ** WARNING: ESN B3BC1494 HAS 2 DUPLICATES! ** FOUND 2 ESNs WITH DUPLICATES! ESN-Count: 49