Artificial intelligent assistant

AWK: To divide a column in userdefined chunksize; and count+sum each entry for every chunk; give average per entry for all chunk I need help to process a column entry via awk. Below are the operations i want to try: * To divide a column in user-defined chunk size; * count and sum each entry for every chunk to eventually give average per entry which will be eventually the chunk size. For instance, below is a list: 1 2 3 4 5 6 7 8 9 10 11 12 Here, I want to use a chunk size of 4 (but in my case it can vary from case to case): * chunk1 1 2 3 4 * chunk2 5 6 7 8 * chunk3 9 10 11 12 After processing, I would like to have: 5 6 7 8 which is the average for the entries in position 1, 2, 3 and 4, respectively, across all chunks.

The following `awk` program would do the job. It assumes the data is stored in `data.txt` in the first column (but can easily be adapted for any other column). It also assumes there are no empty columns, and only complete chunks.


awk -v cs=4 '{if ((i=NR%cs)==0) {n_ch++; i=cs};buf[i]+=$1;} END{for (i=1;i<=cs;i++) printf "%d\
",buf[i]/n_ch}' data.txt


The chunk size is passed to `awk` via the `-v cs= _size_` statement.

It will, for each line, determine the "entry number within the chunk", `i`, via `i = "line number" modulo "chunk size"`, and sum the entries into an array `buf`. Whenever one chunk is complete, the chunk counter `n_ch` is increased.

In the end, we print the average for all entry numbers.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy b03336478bf42b66df950bdff76c9df7