Sponsored Content
Top Forums Shell Programming and Scripting Average of columns with values of other column with same name Post 302743679 by isildur1234 on Thursday 13th of December 2012 06:05:21 AM
Old 12-13-2012
Thank you so much pamu.
It works just great with this file.
Is there any clear reason that you can see that it does not work properly with columns that have spaces in their names?
for example if i try this input:

Code:
Sample	Cq	Sample	Cq	Sample	Cq	Sample	Cq	Sample	Cq
1 WB IN	23.45	1 WB IN	23.45	1 CVS IN	23.96	1 CVS IN	23.14	S1	31.37
1 WB IN	23.53	1 WB IN	23.53	1 CVS IN	23.81	1 CVS IN	23.24	S1	31.49
1 WB IP	24.55	1 WB IN	24.55	1 CVS IN	23.86	1 CVS IN	23.24	S1	31.74
1 CVS IN	23.62	1 CVS IN	23.62	1 CVS IP	22.12	1 CVS IP	38.3	S10	31.13
1 CVS IN	23.46	I CVS IN	21.74	1 CVS IP	22.24	1 CVS IP	21.4	S10	31.1
1 CVS IN	21.74	1 CVS IN	23.33	1 CVS IP	22.22	1 CVS IP	21.36	S10	31.29

it only outputs the first line.

Many thanks again.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check Null values in a file column by column if columns are Not NULLs

Hi All, I have a table with 10 columns. Some columns(2nd,4th,5th,7th,8th and 10th) are Not Null columns. I'll get a tab-delimited file and want to check col by col and generate seperate error code for each col eg:102 if 2nd col value is NULL and 104 if 4th col value is NULL so on... I am a... (7 Replies)
Discussion started by: Mandab
7 Replies

2. Shell Programming and Scripting

how to flip values of two columns and add an extra column

Hi guys, Couldn't find the solution of this problem. Please Help! I have a file- Input_File TC200232 92 30 TC215306 2 74 TC210135 42 14 I want an output file in which if column2>column3, the values are swapped and an additional column with value Rev_Com is... (4 Replies)
Discussion started by: smriti_shridhar
4 Replies

3. Shell Programming and Scripting

Average values in a column based on range

Hi i have data with two columns like below. I want to find average of column values like if the value in column 2 is between 0-250000 the average of column 1 is some xx and average of column2 is ww then if value is 250001-5000000 average of column 1 is yy and average of column 2 is zz. And my... (5 Replies)
Discussion started by: bhargavpbk88
5 Replies

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

5. Shell Programming and Scripting

Add the values in second and third columns with group by on first column.

Hi All, I have a pipe seperated file. I need to add the values in second and third columns with group by on first column. MYFILE_28012012_1115|47|173.90 MYFILE_28012012_1115|4|0.00 MYFILE_28012012_1115|6|22.20 MYFILE_28012012_1116|47|173.90 MYFILE_28012012_1116|4|0.00... (3 Replies)
Discussion started by: angshuman
3 Replies

6. Shell Programming and Scripting

Get the average from column, and eliminate the duplicate values.

Dear Experts, Kindly help me please, I have a big file where there is duplicate values in col 11 till col 23, every 2 rows appers a new numbers, but in each row there is different coordinates x and y in col 57 till col 74. Please i will like to get a single value and average of the x and y... (8 Replies)
Discussion started by: jiam912
8 Replies

7. Linux

To get all the columns in a CSV file based on unique values of particular column

cat sample.csv ID,Name,no 1,AAA,1 2,BBB,1 3,AAA,1 4,BBB,1 cut -d',' -f2 sample.csv | sort | uniq this gives only the 2nd column values Name AAA BBB How to I get all the columns of CSV along with this? (1 Reply)
Discussion started by: sanvel
1 Replies

8. Shell Programming and Scripting

Splitting the numeric vs alpha values in a column to distinct columns

How could i take an input file and split the numeric values from the alpha values (123 vs abc) to distinc columns, and if the source is blank to keep it blank (null) in both of the new columns: So if the source file had a column like: Value: |1 | |2.3| | | |No| I would... (7 Replies)
Discussion started by: driftlogic
7 Replies

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

10. UNIX for Beginners Questions & Answers

Copy columns from one file into another and get sum of column values and row count

I have a file abc.csv, from which I need column 24(PurchaseOrder_TotalCost) to get the sum_of_amounts with date and row count into another file say output.csv abc.csv- UTF-8,,,,,,,,,,,,,,,,,,,,,,,,, ... (6 Replies)
Discussion started by: Tahir_M
6 Replies
Algorithm::Numerical::Sample(3pm)			User Contributed Perl Documentation			 Algorithm::Numerical::Sample(3pm)

NAME
Algorithm::Numerical::Sample - Draw samples from a set SYNOPSIS
use Algorithm::Numerical::Sample qw /sample/; @sample = sample (-set => [1 .. 10000], -sample_size => 100); $sampler = Algorithm::Numerical::Sample::Stream -> new; while (<>) {$sampler -> data ($_)} $random_line = $sampler -> extract; DESCRIPTION
This package gives two methods to draw fair, random samples from a set. There is a procedural interface for the case the entire set is known, and an object oriented interface when the a set with unknown size has to be processed. A: "sample (set => ARRAYREF [,sample_size => EXPR])" The "sample" function takes a set and a sample size as arguments. If the sample size is omitted, a sample of 1 is taken. The keywords "set" and "sample_size" may be preceeded with an optional "-". The function returns the sample list, or a reference to the sample list, depending on the context. B: "Algorithm::Numerical::Sample::Stream" The class "Algorithm::Numerical::Sample::Stream" has the following methods: "new" This function returns an object of the "Algorithm::Numerical::Sample::Stream" class. It will take an optional argument of the form "sample_size => EXPR", where "EXPR" evaluates to the sample size to be taken. If this argument is missing, a sample of size 1 will be taken. The keyword "sample_size" may be preceeded by an optional dash. "data (LIST)" The method "data" takes a list of parameters which are elements of the set we are sampling. Any number of arguments can be given. "extract" This method will extract the sample from the object, and reset it to a fresh state, such that a sample of the same size but from a different set, can be taken. "extract" will return a list in list context, or the first element of the sample in scalar context. CORRECTNESS PROOFS
Algorithm A. Crucial to see that the "sample" algorithm is correct is the fact that when we sample "n" elements from a set of size "N" that the "t + 1"st element is choosen with probability "(n - m)/(N - t)", when already "m" elements have been choosen. We can immediately see that we will never pick too many elements (as the probability is 0 as soon as "n == m"), nor too few, as the probability will be 1 if we have "k" elements to choose from the remaining "k" elements, for some "k". For the proof that the sampling is unbiased, we refer to [3]. (Section 3.4.2, Exercise 3). Algorithm B. It is easy to see that the second algorithm returns the correct number of elements. For a sample of size "n", the first "n" elements go into the reservoir, and after that, the reservoir never grows or shrinks in size; elements only get replaced. A detailed proof of the fairness of the algorithm appears in [3]. (Section 3.4.2, Exercise 7). LITERATURE
Both algorithms are discussed by Knuth [3] (Section 3.4.2). The first algoritm, Selection sampling technique, was discovered by Fan, Muller and Rezucha [1], and independently by Jones [2]. The second algorithm, Reservoir sampling, is due to Waterman. REFERENCES
[1] C. T. Fan, M. E. Muller and I. Rezucha, J. Amer. Stat. Assoc. 57(1962), pp 387 - 402. [2] T. G. Jones, CACM 5(1962), pp 343. [3] D. E. Knuth: The Art of Computer Programming, Volume 2, Third edition. Reading: Addison-Wesley, 1997. ISBN: 0-201-89684-2. DEVELOPMENT
The current sources of this module are found on github, <git://github.com/Abigail/algorithm--numerical--sample.git>. AUTHOR
This package was written by Abigail, cpan@abigail.be. COPYRIGHT and LICENSE Copyright (C) 1998, 1999, 2009, Abigail. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. perl v5.10.1 2010-06-12 Algorithm::Numerical::Sample(3pm)
All times are GMT -4. The time now is 12:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy