Standard Deviation For Every "n" lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Standard Deviation For Every "n" lines
# 8  
Old 01-27-2016
Thank you Rudi, just adding to his comments in case you need each time sets like from 1 to 40, 41 to 80 and so on then you could nullify the values of variables named x and y as follows, whenever there is line completely divided by 40.
Code:
awk '{x+=$2;y+=$2^2;} NR%40==0{print sqrt(y/NR-(x/NR)^2);x=y=""}' Input_file

Again as I haven't seen sample Input_file so this is based on the previous threads communications and provided information only, hope this helps.


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 9  
Old 01-27-2016
Quote:
Originally Posted by RavinderSingh13
Thank you Rudi, just adding to his comments in case you need each time sets like from 1 to 40, 41 to 80 and so on then you could nullify the values of variables named x and y as follows, whenever there is line completely divided by 40.
Code:
awk '{x+=$2;y+=$2^2;} NR%40==0{print sqrt(y/NR-(x/NR)^2);x=y=""}' Input_file

Again as I haven't seen sample Input_file so this is based on the previous threads communications and provided information only, hope this helps.


Thanks,
R. Singh
Thank you Rudic and Ravinder Singh.

Ravi's updated one is what I have been looking for.

But I think to calculate the average for every 40lines (treating 1 to 40 as set1, 41 to 80 as set2 etc), this command is right?

Code:
awk '{sum+=$3} (NR%40)==0{print sum/40; sum=0;}'

# 10  
Old 01-27-2016
"Ravi's updated one" in post#8 is NOT what you've been looking for. Replace y/NR and x/NR by x/40 and y/40, respectively.
This User Gave Thanks to RudiC For This Post:
# 11  
Old 01-27-2016
Quote:
Originally Posted by RudiC
"Ravi's updated one" in post#8 is NOT what you've been looking for. Replace y/NR and x/NR by x/40 and y/40, respectively.
Rudic - In Post8 or Post2 of Ravi?
# 12  
Old 01-27-2016
In post#8. And, add an END section for the residual lines (c.f. post#5)
This User Gave Thanks to RudiC For This Post:
# 13  
Old 01-27-2016
Quote:
Originally Posted by RudiC
In post#8. And, add an END section for the residual lines (c.f. post#5)
I made it like this -

Code:
awk '{x+=$3;y+=$3^2;} NR%40==0{print sqrt(y/40-(x/40)^2);x=y=""}END {print sqrt(y/(NR%40)-(x/(NR%40))^2)}'

Is this what you meant Rudic?

Thank you so much!
# 14  
Old 01-27-2016
Yes.

And, Yes to your question for the average in post#9, provided you add END {print sum/(NR%40
This User Gave Thanks to RudiC For This Post:
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