Standard Deviation For Every "n" lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Standard Deviation For Every "n" lines
# 15  
Old 01-27-2016
Quote:
Originally Posted by RudiC
Yes.

And, Yes to your question for the average in post#9, provided you add END {print sum/(NR%40
Rudic - Thank you so much. Loved your patience and co-operation.

Cheers! SmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilie
# 16  
Old 01-27-2016
There is still a small problem. If the number of lines in your input file is an exact multiple of 40 lines, your script will abort in the END clause with a divide by zero error. Perhaps something more like:
Code:
awk '{x+=$3;y+=$3^2;} NR%40==0{print sqrt(y/40-(x/40)^2);x=y=0} END{if(z=NR%40)print sqrt(y/z-(x/z)^2)}'

or if you want the average and standard deviation:
Code:
awk '{x+=$3;y+=$3^2;} NR%40==0{print x/40,sqrt(y/40-(x/40)^2);x=y=0} END{if(z=NR%40)print x/z,sqrt(y/z-(x/z)^2)}'

Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

3. Shell Programming and Scripting

AWK script for standard deviation / root mean square deviation

I have a file with say 50 columns, each containing a whole lot of data. Each column contains data from a separate simulation, but each simulation is related to the data in the last (REFERENCE) column $50 I need to calculate the RMS deviation for each data line, i.e. column 1 relative to... (12 Replies)
Discussion started by: chrisjorg
12 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Giving "read" from standard input a timeout.

I want to prompt a user for input but I want it to timeout after a specified time if no response is given. I tried the sleep command but this does not work. I am using ksh. Thanks. (10 Replies)
Discussion started by: rello
10 Replies
Login or Register to Ask a Question