sum divided by count

sum divided by count
# 1
06-21-2011
sum divided by count

Dear friends,

I'm stuck with the task below, I would be thankful for all your replies.

INPUT :
OUTPUT : what I need is the daily average prices and volumes , date range is moving window of fixed size ( in this case 4 days) average is calculated this way:
e.g. average for 20110606 : I calculate average of prices and volumes between 20110601 and 20110606
so the average price for 20110606 = 63908026.5 , the same for volume.
Of course I have thousands of dates , so I will need bigger moving window size for example 45 days back (it should be custom)

Last edited by hernand; 06-21-2011 at 05:34 AM..
 hernand View Public Profile for hernand Find all posts by hernand
# 2
06-21-2011
what is the relation b/w the input and output ?
This User Gave Thanks to itkamaraj For This Post:
 itkamaraj View Public Profile for itkamaraj Find all posts by itkamaraj
# 3
06-21-2011
What I need in ouput is the average of the prices, volumes for x days before the date in
output ,
so the one row in the output is :
[date] [average price of x days before] [average volume of x days before]
 hernand View Public Profile for hernand Find all posts by hernand
# 4
06-21-2011
I believe you did a mistake in the last column. But try this:

 yazu View Public Profile for yazu Find all posts by yazu
# 5
06-21-2011
Thanks, you were right, its working perfectly.
Just one thing ,can we make this more customizable?
Something like moving window, where the size of the window will be 10.
So we calculate with days 20110601 - 20110610 , 20110602 - 20110612 etc.
Thanks a lot.
 hernand View Public Profile for hernand Find all posts by hernand
# 6
06-21-2011
It's easy with your examples. But is it possible that boundaries will be of different months, like 20110220 - 20110302?
 yazu View Public Profile for yazu Find all posts by yazu

Copy columns from one file into another and get sum of column values and row count

I have a file abc.csv, from which I need column 24(PurchaseOrder_TotalCost) to get the sum_of_amounts with date and row count into another file say output.csv abc.csv- UTF-8,,,,,,,,,,,,,,,,,,,,,,,,, ...

Shell script count lines and sum numbers from multiple files

I want to count the number of lines, I need this result be a number, and sum the last numeric column, I had done to make this one at time, but I need to make this for a crontab, so, it has to be an script, here is my lines: It counts the number of lines: egrep -i String file_name_201611* |...

Script Shell: Count The sum of numbers in a file

Hi all; Here is my file: V1.3=4 V1.4=5 V1.1=3 V1.2=6 V1.3=6 Please, can you help me to write a script shell that counts the sum of values in my file (4+5+3+6+6) ? Thank you so much for help. Kind regards.

Why sum of recs in awk don't match total rec count?

I'm using awk to determine if a field starting in position 604 for length of 10 is not equal to ALL spaces. It's searching several files which are in the current directory. The below awk indicates that there are 84 records on all files where this field IS NOT equal to ALL spaces ( there are 10...

Count char, sum and change

Hello, I have some problem in counting char of word, sum and change. I'm not sure shell script can do this. Input data: Sam1 BB BB AA AA BB BB BB Sam2 BB BB AA AA AB AB AB Sam3 BB BB BB AA BB BB BB Sam4 AB AB AB AB AB AB AA Sam5 BB BB AA AA BB BB -- If I count in column 2, B is 9...

awk and count sum ?

I have a input.txt file which have 3 fields separate by a comma place, os and timediff in seconds tampa,win7, 2575 tampa,win7, 157619 tampa,win7, 3352 dallas,vista,604799 greenbay,winxp, 14400 greenbay,win7 , 518400 san jose,winxp, 228121 san jose,winxp, 70853 san jose,winxp, 193514...

awk count characters, sum, and divide by another column

Hi All, I am another biologist attempting to parse a large txt file containing several million lines like: tucosnp 56762 T Y 228 228 60 23 .CcCcc,,..c.c,cc,,.C... What I need to do is get the frequency of periods (.) plus commas (,) in column 9, and populate this number into another...

how to count number of rows and sum of column using awk

Hi All, I have the following input which i want to process using AWK. Rows,NC,amount 1,1202,0.192387 2,1201,0.111111 3,1201,0.123456 i want the following output count of rows = 3 ,sum of amount = 0.426954 Many thanks

Getting Sum, Count and Distinct Count of a file

Hi all this is a UNIX question. I have a large flat file with millions of records. col1|col2|col3 1|a|b 2|c|d 3|e|f 3|g|h footer**** I am supposed to calculate the sum of col1 1+2+3+3=9, count of col1 1,2,3,3=4, and distinct count of col1 1,2,3=c3 I would like it if you avoid...

count of sum of row60 files same patter

i have 60 files that have same pattern tgt_abc1.dat tgt_abc2.dat i want to calculate sum of row count of these files and sum these up and populate that in third file. how can i do that?? example tgt_abc1.dat 2000 tgt_abc2.dat 4000 so want to populate in file xyz.dat 6000