Sponsored Content
Top Forums Shell Programming and Scripting Standard Deviation For Every "n" lines Post 302965328 by jacobs.smith on Wednesday 27th of January 2016 10:29:04 AM
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;}'

 

5 More Discussions You Might Find Interesting

1. 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

2. 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

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

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

5. 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
All times are GMT -4. The time now is 08:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy