Hello jiam912,
Could you please try following and let me know if this helps.
wk '{A[substr($0,1,5)+0]=A[substr($0,1,5)+0]>=substr($0,6)+0?A[substr($0,1,5)+0]:substr($0,6)+0;B[substr($0,1,5)+0]=B[substr($0,1,5)+0]<=substr($0,6)+0 && B[substr($0,1,5)+0]?B[substr($0,1,5)+0]:substr($0,6)} END{print "MAX values:";for(i in A){print i OFS A};print "MIN values:";for(j in B){print j OFS B[j]}}' Input_file
Output is as follows.
MAX values:
51000 10012
51020 10012
MIN values:
51000 10002
51020 10002
EDIT: You can try following also to get output in requested form.
awk '{A[substr($0,1,5)+0]=A[substr($0,1,5)+0]>=substr($0,6)+0?A[substr($0,1,5)+0]:substr($0,6)+0;B[substr($0,1,5)+0]=B[substr($0,1,5)+0]<=substr($0,6)+0 && B[substr($0,1,5)+0]?B[substr($0,1,5)+0]:substr($0,6)} END{print "VALUE MAX MIN";for(i in A){print i OFS A OFS B}}' OFS="\t" Input_file
EDIT: Adding a nonone liner form of solution.
awk '{
A[substr($0,1,5)+0]=A[substr($0,1,5)+0]>=substr($0,6)+0?A[substr($0,1,5)+0]:substr($0,6)+0;
B[substr($0,1,5)+0]=B[substr($0,1,5)+0]<=substr($0,6)+0 && B[substr($0,1,5)+0]?B[substr($0,1,5)+0]:substr($0,6)
}
END {
print "VALUE MAX MIN";
for(i in A)
{
print i OFS A OFS B
}
}
' OFS="\t" Input_file
Output will be as follows.
VALUE MAX MIN
51000 10012 10002
51020 10012 10002
Thanks,
R. Singh