Sponsored Content
Top Forums Shell Programming and Scripting AWK novice - calculate the average Post 302469221 by pravin27 on Friday 5th of November 2010 04:33:25 AM
Old 11-05-2010
Try this,

Code:
 awk -F"[. ]" 'NR>1 && $1 != p {print p,s"."a/k,x"."b/k,y"."c/k,"number of measurements for",p,"-",k," and number of measurements with zero value for",p," - " z; k=0;a=0;b=0;c=0;z=0}
{if (/\.0/) {++z};a+=$3;b+=$5;c+=$7;++k;p=$1;s=$2;x=$4;y=$6} END {print p,s"."a/k,x"."b/k,y"."c/k,"number of measurements for",p,"-",k," and number of measurements with zero value for",p," - " z}' inputfile


Last edited by pravin27; 11-05-2010 at 07:43 AM..
This User Gave Thanks to pravin27 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

calculate average of column 2

Hi I have fakebook.csv as following: F1(current date) F2(popularity) F3(name of book) F4(release date of book) 2006-06-21,6860,"Harry Potter",2006-12-31 2006-06-22,,"Harry Potter",2006-12-31 2006-06-23,7120,"Harry Potter",2006-12-31 2006-06-24,,"Harry Potter",2006-12-31... (0 Replies)
Discussion started by: onthetopo
0 Replies

2. UNIX for Dummies Questions & Answers

Use awk to calculate average of column 3

Suppose I have 500 files in a directory and I need to Use awk to calculate average of column 3 for each of the file, how would I do that? (6 Replies)
Discussion started by: grossgermany
6 Replies

3. Programming

calculate average

I have a file which is 2 3 4 5 6 6 so i am writing program in C to calculate mean.. #include<stdio.h> #include<string.h> #include <math.h> double CALL mean(int n , double x) main (int argc, char **argv) { char Buf,SEQ; int i; double result = 0; FILE *fp; (3 Replies)
Discussion started by: cdfd123
3 Replies

4. Shell Programming and Scripting

calculate the average of time series data using AWK

Hi, I have two time series data (below) merged into a file. t1 and t2 are in unit of second I want to calculate the average of V1 every second and count how many times "1" in V2 is occur within a second Input File: t1 V1 t2 V2 10.000000... (5 Replies)
Discussion started by: nica
5 Replies

5. Shell Programming and Scripting

Calculate average time using a script

Hello, I'm hoping to get some help on calculating an average time from a list of times (hour:minute:second). Here's what my list looks like right now, it will grow (I can get the full date or change the formatting of this as well): 07:55:31 09:42:00 08:09:02 09:15:23 09:27:45 09:49:26... (4 Replies)
Discussion started by: jaredhanks
4 Replies

6. Shell Programming and Scripting

Calculate Average AWK

I want to calculate the average line by line of some files with several lines on them, the files are identical, just want to average the 3rd columns of those files.:wall: Example file: File 1 001 0.046 0.667267 001 0.047 0.672028 001 0.048 0.656025 001 0.049 ... (2 Replies)
Discussion started by: AriasFco
2 Replies

7. Shell Programming and Scripting

Calculate average for repeated ID within a data

I have an awk script that gives the following output: Average end-to-end transmission delay 2.7 to 5.7 is 0.635392 seconds Average end-to-end transmission delay 2.1 to 5.1 is 0.66272 seconds Average end-to-end transmission delay 2.1 to 5.1 is 0.691712 seconds Average end-to-end transmission... (4 Replies)
Discussion started by: ENG_MOHD
4 Replies

8. Shell Programming and Scripting

Calculate Average time of one column

Hello dears, I have a log file with records like below and want to get a average of one column based on the search of one specific keyword. 2015-02-07 08:15:28 10.102.51.100 10.112.55.101 "kevin.c" POST ... (2 Replies)
Discussion started by: Newman
2 Replies

9. Shell Programming and Scripting

Calculate average, azimut and distance

Gents, Please i will to get the distance and azimut from 2 coordinates: Usig excel formula i get the correct values, but i will like to do it using awk. Example A 35089.0 50345.016 9 75 1 2101774 77 70 79 483911.6 2380106.9 137.4 1 1 6 1 A 35089.0 50345.01620 75... (8 Replies)
Discussion started by: jiam912
8 Replies

10. Shell Programming and Scripting

Calculate the average per block.

My old school way is a one liner. And will search for average from SAR, to get the data receive rate. But, I dont think it is practical or accurate,. Because it calculates to off peak hours. I am planning to change it. My cron runs every 30 mins. When my cron runs, and my time is 14:47pm,, it will... (1 Reply)
Discussion started by: invinzin21
1 Replies
units(1)						      General Commands Manual							  units(1)

NAME
units - Converts units from one measure to another SYNOPSIS
units [-] [file] DESCRIPTION
The units command converts quantities expressed in one measurement to their equivalents in another. The units command is an interactive command. It prompts you for the unit you want to convert from and the unit you want to convert to. The units command does multiplicative scale changes only. That is, units can convert from one value to another only when the conversion is done with a multiplication factor. For example, units cannot convert between degrees Fahrenheit and degrees Celsius because the value of 32 must be added or subtracted in the conversion. You can specify a quantity as a multiplicative combination of units, optionally preceded by a numeric multiplier. Indicate powers by entering suffixed positive integers and indicate division with a / (slash). The units command recognizes lb as a unit of mass, but considers pound to be the British pound sterling. Compound names are run together (for example, lightyear). Prefix British units differing from their American counterparts with br (for example, brgallon). The /usr/share/lib/units file contains a complete list of the units that the units command uses. Most familiar units, abbreviations, and metric prefixes are recognized by the units command, together with the following: Ratio of circum- ference to diameter. Speed of light. Charge on an electron. Acceleration of gravity. Same as g. Avogadro's number. Pressure head per unit height of water. Astronomical unit. The - argument causes units to display a list of all known units and their conversion values. The file argument specifies an alternative units file to be used instead of the default file units. EXAMPLES
To start the units command, enter: units Now you can try the following examples. To display conversion factors, enter: you have: in you want: cm * 2.540000e+00 / 3.937008e-01 The output from the units command tells you to multiply the number of inches by 2.540000e+00 to get centimeters, and to multiply the number of centimeters by 3.937008e-01 to get inches. These numbers are in standard exponential notation, so 3.937008e-01 means 3.937008 x 10-1, which is the same as 0.3937008. The sec- ond number is always the reciprocal of the first; for example, 2.54 equals 1/0.3937008. To convert a measurement to different units, enter: you have: 5 years you want: microsec * 1.577846e+14 / 6.337753e-15 The output shows that 5 years equals 1.577846 x 1014 microseconds, and that 1 microsecond equals 6.337753 x 10-15 years. To give fractions in measurements, enter: you have: 1|3 mi you want: km * 5.364480e-01 / 1.864114e+00 The | (vertical bar) indicates division, so 1|3 means one-third. This shows that one-third mile is the same as 0.536448 kilometers. To include exponents in measurements, enter: you have: 1.2-5 gal you want: floz * 1.536000e-03 / 6.510417e+02 The expression 1.2-5 gal is the equivalent of 1.2 x 10-5. Do not type an e before the exponent. This example shows that 1.2 x 10-5 (0.000012) gallons equal 1.536 x 10-3 (0.001536) fluid ounces. To specify complex units, enter: you have: gram centimeter/second2 you want: kg-m/sec2 * 1.000000e-05 / 1.000000e+05 The units gram centimeter/second2 mean "grams x centimeters/second2." Similarly, kg-m/sec2 means "kilograms x meters/sec2," which is often read as "kilogram-meters per seconds squared". If the units you specify after you have and you want are incompatible, enter: you have: ft you want: lb conformability 3.048000e-01 m 4.535924e-01 kg The message conformability means the units you specified cannot be converted. Feet measure length, and pounds measure mass, so con- verting from one to the other does not make sense. Therefore, the units command displays the equivalent of each value in standard units. In other words, this example shows that 1 foot equals 0.3048 meters and that 1 pound equals 0.4535924 kilograms. The units command shows the equivalents in meters and kilograms because the command considers these units to be standard measures of length and mass. Entering <Ctrl-d> causes you to exit from the units program. FILES
Contains units and their conversion values. units(1)
All times are GMT -4. The time now is 05:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy