Hi, all
The data is like following:
############## data ####################
time name price
20050616 company2 32
19900112 company1 39
19980223 company2 44
20060523 company1 55
############# job to be done ################
the job is simple, find the starting and ending time ofall companies and calculate their return, e.g., for company1, the return is 55/39-1, for company2, it is 32/44-1.
Following code print out nothing, can anybady tip me the error? your help appreciated!
By the way, suggestion on how to initialize an array with customized value (not null) also appreciated.
Regards
will
#################### code ###############################
awk '{BEGIN{FS=OFS="\t";time=1;tk=2;pr=5}
{ if($time > maxtime[$tk]) {maxtime[tk]=$time; etp[$tk]=$pr};
if (mintime[$tk]=="") {mintime[tk]=$time;stp[tk]=$pr};
if(mintime[$tk]!="" && $time < mintime[$tk]) {mintime[tk]=$time; stp[$tk]=$pr} }
END{ for (s in etp) {if (etp!="" && stp!="") print s, maxtime,etp,mintime,stp, etp/stp-1} }' zzz_tmp
The data is like following:
############## data ####################
time name price
20050616 company2 32
19900112 company1 39
19980223 company2 44
20060523 company1 55
############# job to be done ################
the job is simple, find the starting and ending time ofall companies and calculate their return, e.g., for company1, the return is 55/39-1, for company2, it is 32/44-1.
Following code print out nothing, can anybady tip me the error? your help appreciated!
By the way, suggestion on how to initialize an array with customized value (not null) also appreciated.
Regards
will
#################### code ###############################
awk '{BEGIN{FS=OFS="\t";time=1;tk=2;pr=5}
{ if($time > maxtime[$tk]) {maxtime[tk]=$time; etp[$tk]=$pr};
if (mintime[$tk]=="") {mintime[tk]=$time;stp[tk]=$pr};
if(mintime[$tk]!="" && $time < mintime[$tk]) {mintime[tk]=$time; stp[$tk]=$pr} }
END{ for (s in etp) {if (etp