I deal with names and addresses all the time and I use some old cobol programs. I wanted to do this in awk but my cobol background shows; anyway the program reads a file ( about 20,000 records ) it is a fixed lenght record so I use substr() to get the key, now the trick is that we want to keep the records in an array and as soon as we get 3 keys (records) that are the same print array to a file and if the key of the next record is the same then just keep printing. Now if the key changes and you have less than 3 names in the array print the array to a different file.
Any way I use AWK in windows xp , with EditPlus which is a pleasure to use. this is what I started with it does not work yet and I will fix it but I just wanted some tips on arrays maybe?
Remember this program doesn't do anything yet.
Norm,
Thanx.
Any way I use AWK in windows xp , with EditPlus which is a pleasure to use. this is what I started with it does not work yet and I will fix it but I just wanted some tips on arrays maybe?
Code:
BEGIN {
print "BEG TIME......... "strftime("%H:%M:%S")
save_table[0]=0
}
{
#begin_newfilename:////// add "-A" filename in windows//////
if (NR < 2 )
{begfile=fname=FILENAME
if(match(begfile,/\..+/)){endfile=substr(fname,RSTART,RLENGTH)}
gsub(/\..+/,"",begfile)
fname=begfile"-A"endfile
}
#end_newfilename://////
key=substr($0,77,22)
#save the first record
if (NR < 2){
save_table[0]=0
okey=key}
if (key != okey){
cnt=1
if (save_table[0]==0){
save_table[0]++
next}
okey=key
save_table[save_table[0]]=$0
}
if (save_table[0] < 3)
{save_table[save_table[0]]=$0
save_table[0]++
okey=key
}
#//// TODO ////
cntsel++
}
END {print "INPUT FILENAME... " FILENAME
print "SELECTED RECORDS. " cntsel+0
print "RECORDS ........ " NR
print "END TIME ........ " strftime("%H:%M:%S")
}
Remember this program doesn't do anything yet.
Norm,
Thanx.