This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bash: awk: Calculate average of first 10 rows in column?

Hi all,

I'm working with video data for drug phenotypes on some mutant cell lines. Output is thousands of columns of pixel intensity data vs time (each row being a new frame of the video). I want to normalise the data in each column against an average of the first 10 data points from that column. I'm no geek btw, so go easy!!

Put simply:

  1. I need to take an average of the first 10 rows of the column (and store that average in a new column or document) But I can't work out how to ONLY do that calculation on the first 10 rows rather than on the whole column (147 rows in total)

  2. I need to divide every data point in the column by that average (I can probably work this one out myself, once I've got the answer to question 1!)

Here's an example of the data

https://drive.google.com/open?id=16ZhC-OjNTIpXkWek02BJx2qOgh1Xv889TDTbOdprDYk

Thanks very much!! Ewan

bash awk csv

If you are using Linux you should read head -h.

head -n 10 your_input

1 answer

 awk '(NR<=10) {array[NR]=int($0);next;} (NR==11) {T=0;for(i=1;i<11;i++) T+=array[i]; T=T/10.0; for(i=1;i<11;i++) print array[i]/T;} { print int($0)/T;}' input.txt

Log in to answer this question.