Find the average and the different


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find the average and the different
# 1  
Old 06-19-2013
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:
Code:
Col1 col2 col3 col4 col5
1 20130619 124 sa 150
2 20130619 952 sb 13453
3 20130619 502 sc 91

Yesterday's file:
Code:
Col1 col2 col3 col4 col5
1 20130618 124 sa 130
2 20130618 952 sb 11499
3 20130618 502 sc 100

Code:
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

# 2  
Old 06-19-2013
What about the solutions proposed in your other thread: https://www.unix.com/shell-programmin...ent-files.html ? Did you try to apply what you've learned from them? Show us!
This User Gave Thanks to RudiC For This Post:
# 3  
Old 06-19-2013
there i have give the value which number i have to match, but if i dont know the number how can i do that

Last edited by Shenbaga.d; 06-19-2013 at 05:14 AM..
# 4  
Old 06-19-2013
Could this help you ?
Code:
 
 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[i]"\t\t"sum[i]/2"\n";}}' today yest dbyest

# 5  
Old 06-19-2013
Thanks pravin27,

its working file, but if i want to add "n" no. of files it will work?
# 6  
Old 06-19-2013
Quote:
Originally Posted by Shenbaga.d
there i have give the value which number i have to match, but if i dont know the number how can i do that
If you don't know the number, how do you know what to match? And how should we know, then?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find the average based on similar names in the first column

I have a table, say this: name1 num1 num2 num3 num4 name2 num5 num6 num7 num8 name3 num1 num3 num4 num9 name2 num8 num9 num1 num2 name2 num4 num5 num6 num4 name4 num4 num5 num7 num8 name5 num1 num3 num9 num7 name5 num6 num8 num3 num4 I want a code that will sort my data according... (4 Replies)
Discussion started by: FelipeAd
4 Replies

2. Shell Programming and Scripting

AWK script to split data and find average

Input: 2.58359023380340e+02 1.43758864405595e+02 -7.65700666212508e+00 1.06460208083228e+02 1.26185441783936e+02 -3.41389169427027e+01 -1.40393299309592e+02 -3.07758776849508e+01 1.45067703495838e+02 1.79405834959073e+02 5.06666234594205e+01 OUT 2.0105894389e+02 (average of... (8 Replies)
Discussion started by: chrisjorg
8 Replies

3. Shell Programming and Scripting

How to find the average,min,max ,total count?

Hi , Below is my sample data,I have this 8 column(A,B,C,D,E,F,G,H) in csv file. A , B ,C ,D ,E ,F,G ,H 4141,127337,24,15,20,69,72.0,-3 4141,128864,24,15,20,65,66.0,-1 4141,910053,24,15,4,4,5.0,-1 4141,910383,24,15,22,3,4.0,-1 4141,496969,24,15,14,6,-24.0,-18... (7 Replies)
Discussion started by: vinothsekark
7 Replies

4. Homework & Coursework Questions

Find the Maximum value and average of a column

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to complete a script which will allow me to find: a) reads a value from the keyboard. (ask the... (4 Replies)
Discussion started by: dstewie
4 Replies

5. Shell Programming and Scripting

To find sum & average of 8th field

Hi Friends, I have many files like below. total,0.7%,0.0%,0.2%,0.0%,0.2%,0.7%,98.0% total,1.9%,0.0%,0.4%,0.0%,0.0%,6.8%,90.6% total,0.9%,0.0%,0.4%,0.0%,0.0%,0.0%,98.5% total,1.4%,0.0%,0.7%,0.0%,0.2%,2.9%,94.5% total,0.7%,0.0%,0.4%,0.0%,0.0%,0.9%,97.7%... (13 Replies)
Discussion started by: SunilB2011
13 Replies

6. Shell Programming and Scripting

awk - find average interarrival times for each unique page

All, I have a test file as specified below. 1st col is <arrival time> and 2nd col is <Page #>. I want to find the inter-arrival time of requests for each page # (I've done this part already). Once I have this, I want to calculate the average interarrival time. Note, that I am trying to have the... (11 Replies)
Discussion started by: jontjioe
11 Replies

7. Shell Programming and Scripting

Script to find the average of a given column and also for specified number of rows?

Hi Friends, In continuation to my earlier post https://www.unix.com/shell-programming-scripting/99166-script-find-average-given-column-also-specified-number-rows.html I am extending my problem as follows. Input: Column1 Column2 MAS 1 MAS 4 ... (2 Replies)
Discussion started by: ks_reddy
2 Replies

8. Shell Programming and Scripting

Script to find the average of a given column and also for specified number of rows??

Hi friends I have 100 files in my directory. Each file look like this.. Temp1 Temp2 Temp3 MAS 1 2 3 MAS 4 5 6 MAS 7 8 9 Delhi 10 11 12 Delhi 13 14 15 Delhi 16 17 ... (4 Replies)
Discussion started by: ks_reddy
4 Replies

9. Shell Programming and Scripting

script to find the average number or files?

Anyone has a script or command in UNIX that can take 4 to five different numbers and calculate the average? (2 Replies)
Discussion started by: bbbngowc
2 Replies

10. UNIX Desktop Questions & Answers

How to find no of occurances Finding average time?

Hi, I have MyLog.log file, and it contains "*** response Time 150", I want to develop Unix script like , 1. extract all such occurances in the MyLog.log file and 2. compute the average time taken I am new to Unix, any one can give any idea/sample code for this? Thanks in advance. (1 Reply)
Discussion started by: redlotus72
1 Replies
Login or Register to Ask a Question