Sponsored Content
Top Forums Shell Programming and Scripting Average of a columns from three files Post 303002733 by nans on Thursday 31st of August 2017 09:33:55 AM
Old 08-31-2017
Average of a columns from three files

hello, I have three files in the following order
Code:
==> File1 <==
1    20977000    20977000    A    C    1.00    0,15    15    45
1    115829313    115829313    G    A    0.500    6,7    13    99

==> File2 <==
1    20977000    20977000    A    C    1.00    0,13    13    39
1    115829313    115829313    G    A    0.500    7,7    14    99

==> File3 <==
1    20977000    20977000    A    C    1.00    0,16    16    48
1    115829313    115829313    G    A    0.500    7,10    17    99

I need to take the average of the 8th column from each file and output the average to the first file. So the results should look like

Code:
==> Results <==
1    20977000    20977000    A    C    1.00    0,15    15    45 14.6667
1    115829313    115829313    G    A    0.500    6,7    13    99 14.6667

I am able to calculate the average with this
Code:
awk '{a[FNR]=a[FNR]+$8;b[FNR]++;}END{for(i in a){print i,a[i]/b[i]}}' *.txt

but not able to write it into the first file. Any suggestions ?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Taking the average of two columns and printing it on a new column

Hi, I have a space delimited text file that looks like the following: Aa 100 200 Bb 300 100 Cc X 500 Dd 600 X Basically, I want to take the average of columns 2 and 3 and print it in column 4. However if there is an X in either column 2 or 3, I want to print the non-X value. Therefore... (11 Replies)
Discussion started by: evelibertine
11 Replies

2. Shell Programming and Scripting

Average of columns with values of other column with same name

I have a lot of input files that have the following form: Sample Cq Sample Cq Sample Cq Sample Cq Sample Cq 1WBIN 23.45 1WBIN 23.45 1CVSIN 23.96 1CVSIN 23.14 S1 31.37 1WBIN 23.53 1WBIN 23.53 1CVSIN 23.81 1CVSIN 23.24 S1 31.49 1WBIN 24.55 1WBIN 24.55 1CVSIN 23.86 1CVSIN 23.24 S1 31.74 ... (3 Replies)
Discussion started by: isildur1234
3 Replies

3. Shell Programming and Scripting

How to calculate average of two columns and copy into another file?

Hi, I need help with the awk command. I have a folder with aprox 500 files each one with two columns and I want to print in a new file, the average of column 1 and average of column 2 and the name of each file. Input files are: File-1: 100 99 20 99 50 99 50 99 File-2: 200 85... (3 Replies)
Discussion started by: Lokaps
3 Replies

4. UNIX for Dummies Questions & Answers

Writing a script to take the average of two columns every 3 rows

I have a dataset with 120 columns. I would like to write a script, that takes the average of every two columns, starting from columns 2 and 3, and moving consecutively in frames of 3 columns, all the way until the last column. The first column in the output file would be the averages of columns... (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

Average across multiple columns group by

Hi experts, I want to group by average, for multiple columns starting column $7 until NF, group by ($1-$5), please help For just 7th column, I can do awk ' NR>1{ arr += $7 count += 1 } END{ for (a in arr) { print a, arr/count ... (10 Replies)
Discussion started by: ritakadm
10 Replies

6. Shell Programming and Scripting

Match first two columns and calculate percent of average in third column

I have the need to match the first two columns and when they match, calculate the percent of average for the third columns. The following awk script does not give me the expected results. awk 'NR==FNR {T=$3; next} $1,$2 in T {P=T/$3*100; printf "%s %s %.0f\n", $1, $2, (P>=0)?P:-P}' diff.file... (1 Reply)
Discussion started by: ncwxpanther
1 Replies

7. Shell Programming and Scripting

Match first two columns and average third from multiple files

I have the following format of input from multiple files File 1 24.01 -81.01 1.0 24.02 -81.02 5.0 24.03 -81.03 0.0 File 2 24.01 -81.01 2.0 24.02 -81.02 -5.0 24.03 -81.03 10.0 I need to scan through the files and when the first 2 columns match I... (18 Replies)
Discussion started by: ncwxpanther
18 Replies

8. Emergency UNIX and Linux Support

Average columns based on header name

Hi Friends, I have files with columns like this. This sample input below is partial. Please check below for main file link. Each file will have only two rows. ... (8 Replies)
Discussion started by: jacobs.smith
8 Replies

9. Shell Programming and Scripting

Average across multiple columns - awk

Hi forum members, I'm trying to get an average of multiple columns in a csv file using awk. A small example of my input data is as follows: cu,u3o8,au,ag -9,20,-9,3.6 0.005,30,-9,-9 0.005,50,10,3.44 0.021,-9,8,3.35 The following code seems to do most of what I want gawk -F","... (6 Replies)
Discussion started by: theflamingmoe
6 Replies

10. UNIX for Beginners Questions & Answers

Average of columns

I have files that have the following columns chr pos ref alt sample 1 sample 2 sample 3 chr2 179644035 G A 1,107 0,1 58,67 chr7 151945167 G T 142,101 100,200 500,700 chr13 31789169 CTT CT,C 6,37,8 0,0,0 15,46,89 chr22 ... (3 Replies)
Discussion started by: nans
3 Replies
bon_csv2html(1) 					      General Commands Manual						   bon_csv2html(1)

NAME
bon_csv2html program to convert CSV format Bonnie++ data to a HTML form using tables suitable for display on a web page. NB Lynx can't dis- play this properly, and due to the size it probably requires 1024x768 monitor to display properly. bon_csv2txt program to convert CSV format Bonnie++ data to plain-text format suitable for pasting into an email or reading on a Braille display. DESCRIPTION
They take CSV format (comma-delimited spreadsheet files AKA Comma Seperated Values in MS land) data on standard input and produce HTML or plain text on standard output respectively. FORMAT
This is a list of the fields used in the CSV files format version 2. Format version 1 was the type used in Bonnie++ < 1.90. Before each field I list the field number as well as the name given in the heading 0 format_version Version of the output format in use (1.96) 1 bonnie_version (1.96) 2 name Machine Name 3 concurrency The number of copies of each operation to be run at the same time 4 seed Random number seed 5 file_size Size in megs for the IO tests 6 chunk_size Size of chunks in bytes 7 putc,putc_cpu Results for writing a character at a time K/s,%CPU 9 put_block,put_block_cpu Results for writing a block at a time K/s,%CPU 11 rewrite,rewrite_cpu Results for reading and re-writing a block at a time K/s,%CPU 13 getc,getc_cpu Results for reading a character at a time K/s,%CPU 15 get_block,get_block_cpu Results for reading a block at a time K/s,%CPU 17 seeks,seeks_cpu Results for the seek test seeks/s,%CPU 19 num_files Number of files for file-creation tests (units of 1024 files) 20 max_size The maximum size of files for file-creation tests. Or the type of files for links. 21 min_size The minimum size of files for file-creation tests. 22 num_dirs The number of directories for creation of files in multiple directories. 23 file_chunk_size The size of blocks for writing multiple files. 24 seq_create,seq_create_cpu Rate of creating files sequentially files/s,%CPU 26 seq_stat,seq_stat_cpu Rate of reading/stating files sequentially files/s,%CPU 28 seq_del,seq_del_cpu Rate of deleting files sequentially files/s,%CPU 30 ran_create,ran_create_cpu Rate of creating files in random order files/s,%CPU 32 ran_stat,ran_stat_cpu Rate of deleting files in random order files/s,%CPU 34 ran_del,ran_del_cpu Rate of deleting files in random order files/s,%CPU 36 putc_latency,put_block_latency,rewrite_latency Latency (maximum amount of time for a single operation) for putc, put_block, and reqrite 39 getc_latency,get_block_latency,seeks_latency Latency for getc, get_block, and seeks 42 seq_create_latency,seq_stat_latency,seq_del_latency Latency for seq_create, seq_stat, and seq_del 45 ran_create_latency,ran_stat_latency,ran_del_latency Latency for ran_create, ran_stat, and ran_del A string that starts with '#' is a comment. AUTHOR
These programs were written by Russell Coker <russell@coker.com.au>. May be freely used and distributed without restriction. bon_csv2html(1)
All times are GMT -4. The time now is 08:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy