Find the average and the different

Hi ,

Every day I'll get a file, in that I have to match today's file(20130619) third column to previous files (20130618,20130617), that is 124 present in previous files or not. If it matches then I have take the average values of 5th column of 124 from yesterdays and day before yesterdays file, then I have compare the average value to today's 124 value. Same thinks have to done for 952 and 502.
I can use shell script, Mysql. Please help me. Let me know if you have any doubt.

Today's file:

Col1 col2 col3 col4 col5
1 20130619 124 sa 150
2 20130619 952 sb 13453
3 20130619 502 sc 91

Yesterday's file:

Col1 col2 col3 col4 col5
1 20130618 124 sa 130
2 20130618 952 sb 11499
3 20130618 502 sc 100
Day before Yesterday's file:
Col1 col2 col3 col4 col5
1 20130617 124 sa 115
2 20130617 952 sb 12400
3 20130617 502 sc 97

What about the solutions proposed in your other thread: How to take a Average of numbers from different files? ? Did you try to apply what you've learned from them? Show us!

there i have give the value which number i have to match, but if i dont know the number how can i do that

Could this help you ?

 
 awk 'FNR>1 && NR==FNR{a[$3]=$5;next}
a[$3]{sum[$3]+=$5} END {printf "Col3\tTodaysVal\tAvgVal\n";for(i in sum){printf i"\t"a"\t\t"sum/2"\n";}}' today yest dbyest

Thanks pravin27,

its working file, but if i want to add "n" no. of files it will work?

If you don't know the number, how do you know what to match? And how should we know, then?