Sponsored Content
Top Forums Shell Programming and Scripting Awk based script to find the median of all individual columns in a data file Post 302653407 by ks_reddy on Saturday 9th of June 2012 07:19:52 AM
Old 06-09-2012
The output computation is shown below.

Hi Corona,

Thanks for the reply.
For the input of
Step1,Param1,Param2,Param3 1,2,3,4 2,3,4,5 2,4,5,6 3,0,1,2 3,0,0,0 3,2,1,3
The output is computed like below.
In 1st column(Step1), for the data sample '1' the median for 2,3,4 columns are 2,3,4 itself (as the columns has only one value(odd number).
Similarly for the data sample '2' (repeated twice) the median is (3+4)/2, (4+5)/2, (5+6)/2 which is nothing but 3.5,4.5,5.5.
Similarly for the data sample '3' (repeated thrice) the median for 2,3,4 columns are 0,1,2 as the total number samples in each column(2,3,4) are 3. ( So when we sort each column the values are like this {0,0,2}, {0,1,1}, {0,2,3} so the median for each set is 0,1,2 respectively).
So the final output will be
2,3,4 # Median of columns 2,3,4 when 1st col rows=='1' 3.5,4.5,5.5 #Median of columns 2,3,4 when 1st col rows =='2' 0,1,2 #Median of columns 2,3,4 when 1st col rows=='3'
# So my result is nothing for median of columns 2,3,4 for each unique set of row values in column1.


I hope the median computation is clearly explained now.
Have a look and let me know.

Regards
Sid

---------- Post updated at 04:49 PM ---------- Previous update was at 05:38 AM ----------

Hi Binlib,

Your code is perfect except for two missing ';'s (semicolons),
one after the statement " a[i][NR] = $i "
and one more after the statement " asort(a[i]) "

Thanks a lot for your effort.

Sidda
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk based script to print the "mode(statistics term)" for each column in a data file

Hi All, Thanks all for the continued support so far. Today, I need to find the most occurring string/number(also called mode in statistics terminology) for each column in a data file (.csv type). For one column of data(1.txt) like below Sample 1 2 2 3 4 1 1 1 2 I can find the mode... (6 Replies)
Discussion started by: ks_reddy
6 Replies

2. Shell Programming and Scripting

awk based script to find the average of all the columns in a data file

Hi All, I need the modification for the below mentioned code (found in one more post https://www.unix.com/shell-programming-scripting/27161-script-generate-average-values.html) to find the average values for all the columns(but for a specific rows) and print the averages side by side. I have... (4 Replies)
Discussion started by: ks_reddy
4 Replies

3. Shell Programming and Scripting

awk based script to ignore all columns from a file which contains character strings

Hello All, I have a .CSV file where I expect all numeric data in all the columns other than column headers. But sometimes I get the files (result of statistics computation by other persons) like below( sample data) SNO,Data1,Data2,Data3 1,2,3,4 2,3,4,SOME STRING 3,4,Inf,5 4,5,4,4 I... (9 Replies)
Discussion started by: ks_reddy
9 Replies

4. Shell Programming and Scripting

Help with awk replacing identical columns based on another file

Hello, I am using Awk in UBUNTU 12.04. I have a file like following with three fields and 44706 rows. F1 A A F2 G G F3 A T I have another file like this: AL_1 F1 A A AL_2 F1 A T AL_3 F1 A A AL_1 F2 G G AL_2 F2 G A AL_3 F2 G G BO_1 F1 A A BO_2 F1 A T... (6 Replies)
Discussion started by: Homa
6 Replies

5. Shell Programming and Scripting

awk script to split file into multiple files based on many columns

So I have a space delimited file that I'd like to split into multiple files based on multiple column values. This is what my data looks like 1bc9A02 1 10 1000 FTDLNLVQALRQFLWSFRLPGEAQKIDRMMEAFAQRYCQCNNGVFQSTDTCYVLSFAIIMLNTSLHNPNVKDKPTVERFIAMNRGINDGGDLPEELLRNLYESIKNEPFKIPELEHHHHHH 1ku1A02 1 10... (9 Replies)
Discussion started by: viored
9 Replies

6. UNIX for Dummies Questions & Answers

Median calculator based on id match

I am trying to calculate the median of a column of numbers if they match an ID type on a different column. The input file has 3 columns. The column that has the ID is column 1 and the column with the values I'd like to find the median for is column 3. The file does not need to be sorted. What I... (9 Replies)
Discussion started by: verse123
9 Replies

7. Shell Programming and Scripting

Find columns in a file based on header and print to new file

Hello, I have to fish out some specific columns from a file based on the header value. I have the list of columns I need in a different file. I thought I could read in the list of headers I need, # file with header names of required columns in required order headers_file=$2 # read contents... (11 Replies)
Discussion started by: LMHmedchem
11 Replies

8. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

9. Shell Programming and Scripting

awk script to find data in three file and perform replace operation

Have three files. Any other approach with regards to file concatenation or splitting, etc is appreciated If column55(billngtype) of file1 contains YMNC or YPBC then pick the value of column13(documentnumber). Now find this documentnumber in column1(Billdoc) of file2 and grep the corresponding... (4 Replies)
Discussion started by: as7951
4 Replies

10. UNIX for Advanced & Expert Users

Need Optimization shell/awk script to aggreagte (sum) for all the columns of Huge data file

Optimization shell/awk script to aggregate (sum) for all the columns of Huge data file File delimiter "|" Need to have Sum of all columns, with column number : aggregation (summation) for each column File not having the header Like below - Column 1 "Total Column 2 : "Total ... ...... (2 Replies)
Discussion started by: kartikirans
2 Replies
..::lib::Smokeping::sorters::Median(3)				     SmokePing				    ..::lib::Smokeping::sorters::Median(3)

NAME
Smokeping::sorters::Median - Order the target charts by Median RTT OVERVIEW
Find the charts with the highest Median round trip time. DESCRIPTION
Call the sorter in the charts section of the config file + charts menu = Charts title = The most interesting destinations ++ median sorter = Median(entries=>10) title = Top Median round trip time menu = Median RTT format = Median round trip time %f seconds COPYRIGHT
Copyright (c) 2007 by OETIKER+PARTNER AG. All rights reserved. LICENSE
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. AUTHOR
Tobias Oetiker <tobi@oetiker.ch> 2.6.8 2012-02-26 ..::lib::Smokeping::sorters::Median(3)
All times are GMT -4. The time now is 07:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy