Sponsored Content
Top Forums Shell Programming and Scripting averaging column values with awk Post 302280271 by vgersh99 on Monday 26th of January 2009 11:47:19 AM
Old 01-26-2009
Quote:
Originally Posted by johnmillsbro
thanks. that appears to work. Could you explain the code in detail so I fully grasp that? Im not sure if I understand floating numbers? Also. Now if I wanted then to take the average for each BCxxxxxx ID and subtract the mean from each number would that be equally difficult?
thanks a million. this is all new too me...like learning chinese...

-J
I put comments in the last post with the code - hope it helps.
How do you define "mean" and what's the format of your desired output?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

2. Shell Programming and Scripting

for each different entry in column 1 extract maximum values from column 2 in unix/awk

Hello, I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2 SDF4 -0.211654 SDF4 0.978068 ... (1 Reply)
Discussion started by: Diya123
1 Replies

3. Shell Programming and Scripting

How to averaging column based on first column values

Hello I have file that consist of 2 columns of millions of entries timestamp and throughput I want to find the average (throughput ) for each equal timestamp before change it to proper format e.g : i want to average 2 coloumnd fot all 1308154800 values in column 1 and then print... (4 Replies)
Discussion started by: aadel
4 Replies

4. Shell Programming and Scripting

averaging specific column of multiple files

Hi all, I'm needing help again on scripting. I have weekly files with 3 columns, and I need to do monthly averaging on the values on column 3, the file naming convention is as follows: 20000105.u- 2000:year 01:month 05:day 20000112.u 20000119.u 20000126.u 20000202.u 20020209.u I need to... (15 Replies)
Discussion started by: ida1215
15 Replies

5. Shell Programming and Scripting

Averaging each row with null values

Hi all, I want to compute for the average of a file with null values (NaN) for each row. any help on how to do it. the sample file looks like this. 1.4 1.2 1.5 NaN 1.6 1.3 1.1 NaN 1.3 NaN 2.4 1.3 1.5 NaN 1.5 NaN 1.2 NaN 1.4 NaN I need to do a row-wise averaging such that it will sum only... (14 Replies)
Discussion started by: ida1215
14 Replies

6. UNIX for Dummies Questions & Answers

awk for concatenation of column values

Hello, I have a table as shown below. I want to concatenate values in col2 and col3 based on a value in col4. 1 X Y A 3 Y Z B 4 A W B 5 T W A If col4 is A, then I want to concatenate col3 with itself. Otherwise it should concateneate col2 with col3. 1 X Y YY 3 Y Z YZ... (10 Replies)
Discussion started by: Gussifinknottle
10 Replies

7. Shell Programming and Scripting

Selective Replace awk column values

Hi, I have the following data: 2860377|"DATA1"|"DATA2"|"65343"|"DATA2"|"DATA4"|"11"|"DATA5"|"DATA6"|"65343"|"DATA7"|"0"|"8"|"1"|"NEGATIVE" 32340377|"DATA1"|"DATA2"|"65343"|"DATA2"|"DATA4"|"11"|"DATA5"|"DATA6"|"65343"|"DATA7"|"0"|"8"|"1"|"NEG-DID"... (3 Replies)
Discussion started by: sdohn
3 Replies

8. Shell Programming and Scripting

How to perform averaging of values for particular timestamp using awk or anythoing else??

I have a file of the form. 16:00:26,83.33 16:05:26,83.33 16:10:26,83.33 16:15:26,83.33 16:20:26,90.26 16:25:26,83.33 16:30:26,83.33 17:00:26,83.33 17:05:26,83.33 17:10:26,83.33 17:15:26,83.33 17:20:26,90.26 17:25:26,83.33 17:30:26,83.33 For the timestamp 16:00:00 to 16:55:00, I need to... (5 Replies)
Discussion started by: Saidul
5 Replies

9. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

10. Shell Programming and Scripting

awk script to append suffix to column when column has duplicated values

Please help me to get required output for both scenario 1 and scenario 2 and need separate code for both scenario 1 and scenario 2 Scenario 1 i need to do below changes only when column1 is CR and column3 has duplicates rows/values. This inputfile can contain 100 of this duplicated rows of... (1 Reply)
Discussion started by: as7951
1 Replies
Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagiUserbContributed PerlPerl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers(3pm)

NAME
Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers - Don't use values that don't explain themselves. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
What is a "magic number"? A magic number is a number that appears in code without any explanation; e.g. "$bank_account_balance *= 57.492;". You look at that number and have to wonder where that number came from. Since you don't understand the significance of the number, you don't understand the code. In general, numeric literals other than 0 or 1 in should not be used. Use the constant pragma or the Readonly or Const::Fast modules to give a descriptive name to the number. There are, of course, exceptions to when this rule should be applied. One good example is positioning of objects in some container like shapes on a blueprint or widgets in a user interface. In these cases, the significance of a number can readily be determined by context. The maximum number of violations per document for this policy defaults to 10. Ways in which this module applies this rule. By default, this rule is relaxed in that 2 is permitted to allow for common things like alternation, the STDERR file handle, etc.. Numeric literals are allowed in "use" and "require" statements to allow for things like Perl version restrictions and Test::More plans. Declarations of $VERSION package variables are permitted. Use of "Readonly", "Readonly::Scalar", "Readonly::Array", and "Readonly::Hash" from the Readonly module are obviously valid, but use of "Readonly::Scalar1", "Readonly::Array1", and "Readonly::Hash1" are specifically not supported. Use of binary, exponential, hexadecimal, octal, and version numbers, even for 0 and 1, outside of "use"/"require"/"Readonly" statements aren't permitted (but you can change this). There is a special exemption for accessing the last element of an array, i.e. $x[-1]. $x = 0; # ok $x = 0.0; # ok $x = 1; # ok $x = 1.0; # ok $x = 1.5; # not ok $x = 0b0 # not ok $x = 0b1 # not ok $x = 0x00 # not ok $x = 0x01 # not ok $x = 000 # not ok $x = 001 # not ok $x = 0e1 # not ok $x = 1e1 # not ok $frobnication_factor = 42; # not ok use constant FROBNICATION_FACTOR => 42; # ok use 5.6.1; # ok use Test::More plan => 57; # ok plan tests => 39; # ok our $VERSION = 0.22; # ok $x = $y[-1] # ok $x = $y[-2] # not ok foreach my $solid (1..5) { # not ok ... } use Readonly; Readonly my $REGULAR_GEOMETRIC_SOLIDS => 5; foreach my $solid (1..$REGULAR_GEOMETRIC_SOLIDS) { #ok ... } CONFIGURATION
This policy has four options: "allowed_values", "allowed_types", "allow_to_the_right_of_a_fat_comma", and "constant_creator_subroutines". "allowed_values" The "allowed_values" parameter is a whitespace delimited set of permitted number values; this does not affect the permitted formats for numbers. The defaults are equivalent to having the following in your .perlcriticrc: [ValuesAndExpressions::ProhibitMagicNumbers] allowed_values = 0 1 2 Note that this policy forces the values 0 and 1 into the permitted values. Thus, specifying no values, allowed_values = is the same as simply listing 0 and 1: allowed_values = 0 1 The special "all_integers" value, not surprisingly, allows all integral values to pass, subject to the restrictions on number types. Ranges can be specified as two (possibly fractional) numbers separated by two periods, optionally suffixed with an increment using the Perl 6 ":by()" syntax. E.g. allowed_values = 7..10 will allow 0, 1, 7, 8, 9, and 10 as literal values. Using fractional values like so allowed_values = -3.5..-0.5:by(0.5) will permit -3.5, -3, -2.5, -2, -2.5, -1, -0.5, 0, and 1. Unsurprisingly, the increment defaults to 1, which means that allowed_values = -3.5..-0.5 will make -3.5, -2.5, -2.5, -0.5, 0, and 1 valid. Ranges are not lazy, i.e. you'd better have a lot of memory available if you use a range of "1..1000:by(0.01)". Also remember that all of this is done using floating-point math, which means that "1..10:by(0.3333)" is probably not going to be very useful. Specifying an upper limit that is less than the lower limit will result in no values being produced by that range. Negative increments are not permitted. Multiple ranges are permitted. To put this all together, the following is a valid, though not likely to be used, .perlcriticrc entry: [ValuesAndExpressions::ProhibitMagicNumbers] allowed_values = 3.1415269 82..103 -507.4..57.8:by(0.2) all_integers "allowed_types" The "allowed_types" parameter is a whitespace delimited set of subclasses of PPI::Token::Number. Decimal integers are always allowed. By default, floating-point numbers are also allowed. For example, to allow hexadecimal literals, you could configure this policy like [ValuesAndExpressions::ProhibitMagicNumbers] allowed_types = Hex but without specifying anything for "allowed_values", the allowed hexadecimal literals will be 0x00, 0x01, and 0x02. Note, also, as soon as you specify a value for this parameter, you must include "Float" in the list to continue to be able to use floating point literals. This effect can be used to restrict literals to only decimal integers: [ValuesAndExpressions::ProhibitMagicNumbers] allowed_types = If you permit exponential notation, you automatically also allow floating point values because an exponential is a subclass of floating- point in PPI. "allow_to_the_right_of_a_fat_comma" If this is set, you can put any number to the right of a fat comma. my %hash = ( a => 4512, b => 293 ); # ok my $hash_ref = { a => 4512, b => 293 }; # ok some_subroutine( a => 4512, b => 293 ); # ok Currently, this only means directly to the right of the fat comma. By default, this value is true. "constant_creator_subroutines" This parameter allows you to specify the names of subroutines that create constants, in addition to "Readonly", "Const::Fast", and friends. For example, if you use a custom "Const::Fast"-like module that supports a "create_constant" subroutine to create constants, you could add something like the following to your .perlcriticrc: [ValuesAndExpressions::ProhibitMagicNumbers] constant_creator_subroutines = create_constant If you have more than one name to add, separate them by whitespace. The subroutine name should appear exactly as it is in your code. For example, if your code does not import the creating subroutine subroutine, you would need to configure this policy as something like [ValuesAndExpressions::ProhibitMagicNumbers] constant_creator_subroutines = create_constant Constant::Create::create_constant BUGS
There is currently no way to permit version numbers in regular code, even if you include them in the "allowed_types". Some may actually consider this a feature. AUTHOR
Elliot Shank "<perl@galumph.com>" COPYRIGHT
Copyright (c) 2006-2011 Elliot Shank. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.14.2 2012-06-0Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers(3pm)
All times are GMT -4. The time now is 08:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy