Sponsored Content
Full Discussion: sum divided by count
Top Forums Shell Programming and Scripting sum divided by count Post 302532440 by hernand on Tuesday 21st of June 2011 02:46:26 AM
Old 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 :
Code:
Date         Price       Volume
20110601    73052811.61    2845833
20110602    61489062.96    9909230
20110603    72790724.65   1108927
20110606    48299507.20    7435881
20110607    62084372.76    7980464
etc.

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)
Code:
DATE       AVERAGE_PRICE   AVERAGE_VOLUME
20110601   73052812   12845833       
20110602   67270937   11377532       
20110603   69110866   11281445       
20110606   63908027   10320054       
20110607   63543296   9852135.8
etc.


Last edited by hernand; 06-21-2011 at 04:34 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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 (1 Reply)
Discussion started by: er_zeeshan05
1 Replies

2. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: singhabhijit
4 Replies

3. UNIX for Dummies Questions & Answers

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 (2 Replies)
Discussion started by: pistachio
2 Replies

4. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: peromhc
1 Replies

5. Shell Programming and Scripting

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... (5 Replies)
Discussion started by: sabercats
5 Replies

6. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: awil
3 Replies

7. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: mjf
2 Replies

8. Shell Programming and Scripting

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. (3 Replies)
Discussion started by: chercheur111
3 Replies

9. Shell Programming and Scripting

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* |... (5 Replies)
Discussion started by: Elly
5 Replies

10. UNIX for Beginners Questions & Answers

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,,,,,,,,,,,,,,,,,,,,,,,,, ... (6 Replies)
Discussion started by: Tahir_M
6 Replies
MINCAVERAGE(1)							 MINC User's Guide						    MINCAVERAGE(1)

NAME
mincaverage - average minc files SYNOPSIS
mincaverage [<options>] <in1>.mnc [<in2>.mnc...] <out>.mnc DESCRIPTION
Mincaverage averages minc files together. A range of optional behaviour is permitted as well: pre-normalizing volumes, creating a standard deviation volume, averaging over a specified dimension of the input files. OPTIONS
Note that options can be specified in abbreviated form (as long as they are unique) and can be given anywhere on the command line. General options -2 Create a MINC 2.0 format output file. -clobber Overwrite an existing file. -noclobber Don't overwrite an existing file (default). -verbose Print out progress information for each chunk of data copied (default). -quiet Do not print out progress information. -debug Print extra information (e.g. normalization factors). -filelist filename Specify a file containing a list of input file names. If "-" is given, then file names are read from stdin. If this option is given, then there should be no input file names specified on the command line. Empty lines in the input file are ignored. -max_buffer_size_in_kb buffer-size Specify the maximum size of the internal buffers (in kbytes). Default is 4096 kbytes. Output type options These options control the storage precision and size of individual voxel values in the output file. -filetype Don't do any type conversion (default). -byte Write out 8-bit integer values. -short Write out 16-bit integer values. -int Write out 32-bit integer values. -long Superseded by -int. -float Write out single-precision floating point values. -double Write out double-precision floating point values. -signed Write out values as signed integers (default for short and long). Ignored for floating point types. -unsigned Write out values as unsigned integers (default for byte). Ignored for floating point types. -range min max specifies the valid range of output voxel values in their integer representation. Default is the full range for the type and sign. This option is ignored for floating point values. For it to have any effect, you must specify a type. Averaging options -normalize Normalize volumes to their global average before averaging them (based on the mean of voxels with value greater than 2 percent of full range above the minimum). -nonormalize Do not normalize volumes (default). -sdfile sdfile.mnc Specify the name of an output standard deviation file, to be calculated in addition the mean that is normally calculated. -copy_header Copy all of the additional header information from the first input file (default for one input file). -nocopy_header Do not copy additional header information (default for many input files). -avgdim dimname Specify the name of a dimension over which we should be averaging (or calculating standard deviation). If normalization is done, it still only applies to separate files only - no normalization is done within a file. -binarize Binarize the input volumes before calculating the average. The binarization is done by specifying a range of values that contribute 1 to the average. Normalization of the input is not permitted when performing binarization. -binrange min max Specify the range of values for binarization. -binvalue value Specify a single legal value (integer) for binarization. The range is set to be +/- 0.5 around this value to achieve an effective rounding of input values. -weights <w1,w2,...> Specify a series of weights for averaging. The number of weighting values must match the number of input files and the values must be provided as a single argument with commas or spaces as separators. The sum of the weights must be non-zero. If weights are used with an averaging dimension, then only one input file can be specified. -width_weighted This option can only be used when averaging across a dimension (-avgdim option). It specifies that weighting should be done using the width variable that corresponds to the averaging dimension. For example, using -width_weighted with -avgdim time will use the time-width variable to weight the values. Generic options for all commands: -help Print summary of command-line options and exit. -version Print the program's version number and exit. AUTHOR
Peter Neelin COPYRIGHTS
Copyright (C) 1995 by Peter Neelin $Date: 2004-05-20 21:52:07 $ MINCAVERAGE(1)
All times are GMT -4. The time now is 11:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy